/*Function to delete file from a directory. Input:void Output:int */ int delete_file() { int fd_cat = -1; int ret = -1; int status = -1; char *filename = NULL; filename=(char*)calloc(1,FILE_SIZE); fd_cat =open("filecatalog.txt",O_RDONLY); if (fd_cat< 1) { fprintf(stderr,"%s\n",strerror(errno)); goto out; } printf("\n deduped files are\n"); ret=readfilecatalog(); if (ret== -1) { fprintf(stderr,"%s\n",strerror(errno)); goto out; } printf("\nSelect the file you want to delete\n"); while (scanf("%s",filename) <= 0); printf("\nFILE%s",filename); status = remove(filename); if( status== 0 ) printf("\nFile deleted successfully.\n"); else { printf("\nUnable to delete the file\n"); perror("\nError\n"); goto out; } ret=0; out: clean_buff(&filename); return ret; }
/*Function to enter a filename that has to be restored. Input:void Output:int */ int restore_file() { int fd_cat = -1; int ret = -1; char* path = NULL; printf("\ndeduped files\n"); ret=readfilecatalog(); if (ret== -1) { goto out; } path=(char*)calloc(1,FILE_SIZE); out4:printf("\nEnter the exact and full path of dedup file to be restored\n"); scanf("%s",path); ret=comparepath(path); if (ret== -1) { goto out; } if (ret== 1) { printf("\nPlease enter valid full path of file"); goto out4; } ret=restorefile(path); if (ret== -1) { goto out; } ret=0; out: clean_buff(&path); return ret; }