//Config file void loadConfigFile() { printf("Start load config file\n"); TSFile fileHandle; const int bufferSize = 1000; char buffer[bufferSize]; memset(buffer,'\0', bufferSize); File_open(&fileHandle,"C:\\Users\\loki.chuang\\Desktop\\MobileDesc.txt", O_RDONLY); File_read(&fileHandle, buffer, bufferSize); File_close(&fileHandle); printAllChar(buffer, bufferSize); }
int File_copyTo( const IFile* self, const IPath* targetPath, int force ) { bool status = 0; char* target = NULL; IFile* target_file = NULL; IDirectory* target_dir = new_Directory_path( targetPath ); if ( Directory_exists( target_dir ) ) { target = CharString_cat3( Path_getCommon( targetPath ), "/", Path_getBasename( self->path ) ); } else { target = CharString_copy( Path_getCommon( targetPath ) ); } target_file = new_File( target ); if ( !File_exists( target_file ) || force ) { if ( File_open( target_file, "w" ) ) { byte buffer[256]; int read; while ( (read = File_read( self, buffer, 256 )) ) { File_write( target_file, buffer, read ); status = 1; } if ( !status ) { fprintf( stdout, "File.c::copyTo: could not copy data\n" ); } } File_close( target_file ); } free_Directory( target_dir ); free_File( target_file ); free_CharString( target ); return status; }
int main(void) { int fd; InputStream_T in = NULL; Bootstrap(); // Need to initialize library printf("============> Start InputStream Tests\n\n"); printf("=> Test0: create/destroy the stream\n"); { in = InputStream_new(File_open(DATA, "r")); assert(!InputStream_isClosed(in)); File_close(InputStream_getDescriptor(in)); InputStream_free(&in); assert(in == NULL); } printf("=> Test0: OK\n\n"); printf("=> Test1: get/set timeout\n"); { assert((fd = File_open(DATA, "r")) >= 0); in = InputStream_new(fd); printf("\tCurrent timeout: %lldms\n", (long long)InputStream_getTimeout(in)); InputStream_setTimeout(in, TIMEOUT); assert(InputStream_getTimeout(in) == TIMEOUT); printf("\tTimeout set to: %dms\n", TIMEOUT); File_close(fd); InputStream_free(&in); } printf("=> Test1: OK\n\n"); printf("=> Test2: read file by characters\n"); { int byte; int byteno = 0; char content[][1] = {"l", "i", "n", "e", "1", "\n", "l", "i", "n", "e", "2", "\n", "l", "i", "n", "e", "3", "\n"}; assert((fd = File_open(DATA, "r")) >= 0); in = InputStream_new(fd); while ((byte = InputStream_read(in)) > 0) { assert(byte == *content[byteno++]); } File_close(fd); InputStream_free(&in); } printf("=> Test2: OK\n\n"); printf("=> Test3: read file by lines\n"); { int lineno = 0; char line[STRLEN]; char content[][STRLEN] = {"line1\n", "line2\n", "line3\n"}; assert((fd = File_open(DATA, "r")) >= 0); in = InputStream_new(fd); while (InputStream_readLine(in, line, sizeof(line))) { assert(Str_isEqual(content[lineno++], line)); } File_close(fd); InputStream_free(&in); } printf("=> Test3: OK\n\n"); printf("=> Test4: read file by bytes\n"); { char array[STRLEN]; char content[] = "line1\nline2\nline3\n"; memset(array, 0, STRLEN); assert((fd = File_open(DATA, "r")) >= 0); in = InputStream_new(fd); while (InputStream_readBytes(in, array, sizeof(array)-1)) { assert(Str_isEqual(content, array)); } File_close(fd); InputStream_free(&in); } printf("=> Test4: OK\n\n"); printf("=> Test5: read a large file\n"); { if ((fd = File_open("/usr/share/dict/words", "r")) >= 0) { int n = 0; char array[2][STRLEN + 1]; in = InputStream_new(fd); for (int i = 0; ((n = InputStream_readBytes(in, array[i], STRLEN)) > 0); i = i ? 0 : 1) assert(strncmp(array[0], array[1], STRLEN/2) != 0); // ensure that InputStream buffer is filled anew File_rewind(fd); // Test read data larger than InputStream's internal buffer int filesize = (int)File_size("/usr/share/dict/words"); char *bigarray = CALLOC(1, filesize + 1); n = InputStream_readBytes(in, bigarray, filesize); assert(n == filesize); File_close(fd); InputStream_free(&in); FREE(bigarray); } else ERROR("\t/usr/share/dict/words not available -- skipping test\n"); } printf("=> Test5: OK\n\n"); printf("=> Test6: wrong descriptor - expecting read fail\n"); { in = InputStream_new(999); TRY assert(InputStream_read(in) != -1); printf("Test6: Failed"); exit(1); // Should not come here CATCH(AssertException) // Passed END_TRY; InputStream_free(&in); } printf("=> Test6: OK\n\n"); printf("============> InputStream Tests: OK\n\n"); return 0; }
Errors Command_compare(StringList *archiveFileNameList, EntryList *includeEntryList, PatternList *excludePatternList, JobOptions *jobOptions, ArchiveGetCryptPasswordFunction archiveGetCryptPasswordFunction, void *archiveGetCryptPasswordUserData ) { byte *archiveBuffer,*buffer; FragmentList fragmentList; String archiveFileName; Errors failError; Errors error; ArchiveInfo archiveInfo; ArchiveFileInfo archiveFileInfo; ArchiveEntryTypes archiveEntryType; FragmentNode *fragmentNode; assert(archiveFileNameList != NULL); assert(includeEntryList != NULL); assert(excludePatternList != NULL); assert(jobOptions != NULL); /* allocate resources */ archiveBuffer = (byte*)malloc(BUFFER_SIZE); if (archiveBuffer == NULL) { HALT_INSUFFICIENT_MEMORY(); } buffer = malloc(BUFFER_SIZE); if (buffer == NULL) { free(archiveBuffer); HALT_INSUFFICIENT_MEMORY(); } FragmentList_init(&fragmentList); archiveFileName = String_new(); failError = ERROR_NONE; while ( !StringList_empty(archiveFileNameList) && (failError == ERROR_NONE) ) { StringList_getFirst(archiveFileNameList,archiveFileName); printInfo(1,"Comparing archive '%s':\n",String_cString(archiveFileName)); /* open archive */ error = Archive_open(&archiveInfo, archiveFileName, jobOptions, archiveGetCryptPasswordFunction, archiveGetCryptPasswordUserData ); if (error != ERROR_NONE) { printError("Cannot open archive file '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (failError == ERROR_NONE) failError = error; continue; } /* read files */ while ( !Archive_eof(&archiveInfo) && (failError == ERROR_NONE) ) { /* get next archive entry type */ error = Archive_getNextArchiveEntryType(&archiveInfo, &archiveFileInfo, &archiveEntryType ); if (error != ERROR_NONE) { printError("Cannot not read next entry in archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (failError == ERROR_NONE) failError = error; break; } switch (archiveEntryType) { case ARCHIVE_ENTRY_TYPE_FILE: { String fileName; FileInfo fileInfo; uint64 fragmentOffset,fragmentSize; FragmentNode *fragmentNode; // FileInfo localFileInfo; FileHandle fileHandle; bool equalFlag; uint64 length; ulong n; ulong diffIndex; /* read file */ fileName = String_new(); error = Archive_readFileEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, NULL, fileName, &fileInfo, &fragmentOffset, &fragmentSize ); if (error != ERROR_NONE) { printError("Cannot not read 'file' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(fileName); if (failError == ERROR_NONE) failError = error; break; } if ( (List_empty(includeEntryList) || EntryList_match(includeEntryList,fileName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT) ) { printInfo(2," Compare file '%s'...",String_cString(fileName)); /* check file */ if (!File_exists(fileName)) { printInfo(2,"FAIL!\n"); printError("File '%s' not found!\n",String_cString(fileName)); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILE_NOT_FOUND; } break; } if (File_getType(fileName) != FILE_TYPE_FILE) { printInfo(2,"FAIL!\n"); printError("'%s' is not a file!\n",String_cString(fileName)); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_WRONG_FILE_TYPE; } break; } /* get file fragment list */ fragmentNode = FragmentList_find(&fragmentList,fileName); if (fragmentNode == NULL) { fragmentNode = FragmentList_add(&fragmentList,fileName,fileInfo.size); } //FragmentList_print(fragmentNode,String_cString(fileName)); /* open file */ error = File_open(&fileHandle,fileName,FILE_OPENMODE_READ); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot open file '%s' (error: %s)\n", String_cString(fileName), Errors_getText(error) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = error; } continue; } /* check file size */ if (fileInfo.size != File_getSize(&fileHandle)) { printInfo(2,"FAIL!\n"); printError("'%s' differ in size: expected %lld bytes, found %lld bytes\n", String_cString(fileName), fileInfo.size, File_getSize(&fileHandle) ); File_close(&fileHandle); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILES_DIFFER; } continue; } /* check file content */ error = File_seek(&fileHandle,fragmentOffset); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot read file '%s' (error: %s)\n", String_cString(fileName), Errors_getText(error) ); File_close(&fileHandle); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = error; } continue; } length = 0; equalFlag = TRUE; diffIndex = 0; while ((length < fragmentSize) && equalFlag) { n = MIN(fragmentSize-length,BUFFER_SIZE); /* read archive, file */ error = Archive_readData(&archiveFileInfo,archiveBuffer,n); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot not read content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (failError == ERROR_NONE) failError = error; break; } error = File_read(&fileHandle,buffer,n,NULL); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot read file '%s' (error: %s)\n", String_cString(fileName), Errors_getText(error) ); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } /* compare */ diffIndex = compare(archiveBuffer,buffer,n); equalFlag = (diffIndex >= n); if (!equalFlag) { printInfo(2,"FAIL!\n"); printError("'%s' differ at offset %llu\n", String_cString(fileName), fragmentOffset+length+(uint64)diffIndex ); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILES_DIFFER; } break; } length += n; } File_close(&fileHandle); if (failError != ERROR_NONE) { Archive_closeEntry(&archiveFileInfo); String_delete(fileName); continue; } #if 0 /* get local file info */ /* check file time, permissions, file owner/group */ #endif /* 0 */ printInfo(2,"ok\n"); /* add fragment to file fragment list */ FragmentList_addEntry(fragmentNode,fragmentOffset,fragmentSize); /* discard fragment list if file is complete */ if (FragmentList_checkEntryComplete(fragmentNode)) { FragmentList_remove(&fragmentList,fragmentNode); } /* free resources */ } else { /* skip */ printInfo(3," Compare '%s'...skipped\n",String_cString(fileName)); } /* close archive file, free resources */ Archive_closeEntry(&archiveFileInfo); String_delete(fileName); } break; case ARCHIVE_ENTRY_TYPE_IMAGE: { String imageName; DeviceInfo deviceInfo; uint64 blockOffset,blockCount; FragmentNode *fragmentNode; DeviceHandle deviceHandle; bool equalFlag; uint64 block; ulong bufferBlockCount; ulong diffIndex; /* read image */ imageName = String_new(); error = Archive_readImageEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, NULL, imageName, &deviceInfo, &blockOffset, &blockCount ); if (error != ERROR_NONE) { printError("Cannot not read 'image' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(imageName); if (failError == ERROR_NONE) failError = error; break; } if ( (List_empty(includeEntryList) || EntryList_match(includeEntryList,imageName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,imageName,PATTERN_MATCH_MODE_EXACT) ) { printInfo(2," Compare image '%s'...",String_cString(imageName)); /* check if device exists */ if (!File_exists(imageName)) { printInfo(2,"FAIL!\n"); printError("Device '%s' not found!\n",String_cString(imageName)); Archive_closeEntry(&archiveFileInfo); String_delete(imageName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILE_NOT_FOUND; } break; } /* get image fragment list */ fragmentNode = FragmentList_find(&fragmentList,imageName); if (fragmentNode == NULL) { fragmentNode = FragmentList_add(&fragmentList,imageName,deviceInfo.size); } /* open device */ error = Device_open(&deviceHandle,imageName,DEVICE_OPENMODE_READ); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot open file '%s' (error: %s)\n", String_cString(imageName), Errors_getText(error) ); Archive_closeEntry(&archiveFileInfo); String_delete(imageName); if (jobOptions->stopOnErrorFlag) { failError = error; } continue; } /* check image size */ if (deviceInfo.size != Device_getSize(&deviceHandle)) { printInfo(2,"FAIL!\n"); printError("'%s' differ in size: expected %lld bytes, found %lld bytes\n", String_cString(imageName), deviceInfo.size, Device_getSize(&deviceHandle) ); Device_close(&deviceHandle); Archive_closeEntry(&archiveFileInfo); String_delete(imageName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILES_DIFFER; } continue; } /* check image content */ error = Device_seek(&deviceHandle,blockOffset*(uint64)deviceInfo.blockSize); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot read file '%s' (error: %s)\n", String_cString(imageName), Errors_getText(error) ); Device_close(&deviceHandle); Archive_closeEntry(&archiveFileInfo); String_delete(imageName); if (jobOptions->stopOnErrorFlag) { failError = error; } continue; } block = 0LL; equalFlag = TRUE; diffIndex = 0; while ((block < blockCount) && equalFlag) { assert(deviceInfo.blockSize > 0); bufferBlockCount = MIN(blockCount-block,BUFFER_SIZE/deviceInfo.blockSize); /* read archive, file */ error = Archive_readData(&archiveFileInfo,archiveBuffer,bufferBlockCount*deviceInfo.blockSize); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot not read content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (failError == ERROR_NONE) failError = error; break; } error = Device_read(&deviceHandle,buffer,bufferBlockCount*deviceInfo.blockSize,NULL); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot read file '%s' (error: %s)\n", String_cString(imageName), Errors_getText(error) ); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } /* compare */ diffIndex = compare(archiveBuffer,buffer,bufferBlockCount*deviceInfo.blockSize); equalFlag = (diffIndex >= bufferBlockCount*deviceInfo.blockSize); if (!equalFlag) { printInfo(2,"FAIL!\n"); printError("'%s' differ at offset %llu\n", String_cString(imageName), blockOffset*(uint64)deviceInfo.blockSize+block*(uint64)deviceInfo.blockSize+(uint64)diffIndex ); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILES_DIFFER; } break; } block += (uint64)bufferBlockCount; } Device_close(&deviceHandle); if (failError != ERROR_NONE) { Archive_closeEntry(&archiveFileInfo); String_delete(imageName); continue; } #if 0 /* get local file info */ /* check file time, permissions, file owner/group */ #endif /* 0 */ printInfo(2,"ok\n"); /* add fragment to file fragment list */ FragmentList_addEntry(fragmentNode,blockOffset*(uint64)deviceInfo.blockSize,blockCount*(uint64)deviceInfo.blockSize); /* discard fragment list if file is complete */ if (FragmentList_checkEntryComplete(fragmentNode)) { FragmentList_remove(&fragmentList,fragmentNode); } /* free resources */ } else { /* skip */ printInfo(3," Compare '%s'...skipped\n",String_cString(imageName)); } /* close archive file, free resources */ Archive_closeEntry(&archiveFileInfo); String_delete(imageName); } break; case ARCHIVE_ENTRY_TYPE_DIRECTORY: { String directoryName; FileInfo fileInfo; // String localFileName; // FileInfo localFileInfo; /* read directory */ directoryName = String_new(); error = Archive_readDirectoryEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, directoryName, &fileInfo ); if (error != ERROR_NONE) { printError("Cannot not read 'directory' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(directoryName); if (failError == ERROR_NONE) failError = error; break; } if ( (List_empty(includeEntryList) || EntryList_match(includeEntryList,directoryName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,directoryName,PATTERN_MATCH_MODE_EXACT) ) { printInfo(2," Compare directory '%s'...",String_cString(directoryName)); /* check directory */ if (!File_exists(directoryName)) { printInfo(2,"FAIL!\n"); printError("Directory '%s' does not exists!\n",String_cString(directoryName)); Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILE_NOT_FOUND; } break; } if (File_getType(directoryName) != FILE_TYPE_DIRECTORY) { printInfo(2,"FAIL!\n"); printError("'%s' is not a directory!\n", String_cString(directoryName) ); Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_WRONG_FILE_TYPE; } break; } #if 0 /* get local file info */ error = File_getFileInfo(directoryName,&localFileInfo); if (error != ERROR_NONE) { printError("Cannot not read local directory '%s' (error: %s)!\n", String_cString(directoryName), Errors_getText(error) ); Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); if (failError == ERROR_NONE) failError = error; break; } /* check file time, permissions, file owner/group */ #endif /* 0 */ printInfo(2,"ok\n"); /* free resources */ } else { /* skip */ printInfo(3," Compare '%s'...skipped\n",String_cString(directoryName)); } /* close archive file */ Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); } break; case ARCHIVE_ENTRY_TYPE_LINK: { String linkName; String fileName; FileInfo fileInfo; String localFileName; // FileInfo localFileInfo; /* read link */ linkName = String_new(); fileName = String_new(); error = Archive_readLinkEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, linkName, fileName, &fileInfo ); if (error != ERROR_NONE) { printError("Cannot not read 'link' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(fileName); String_delete(linkName); if (failError == ERROR_NONE) failError = error; break; } if ( (List_empty(includeEntryList) || EntryList_match(includeEntryList,linkName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,linkName,PATTERN_MATCH_MODE_EXACT) ) { printInfo(2," Compare link '%s'...",String_cString(linkName)); /* check link */ if (!File_exists(linkName)) { printInfo(2,"FAIL!\n"); printError("Link '%s' -> '%s' does not exists!\n", String_cString(linkName), String_cString(fileName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILE_NOT_FOUND; } break; } if (File_getType(linkName) != FILE_TYPE_LINK) { printInfo(2,"FAIL!\n"); printError("'%s' is not a link!\n", String_cString(linkName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_WRONG_FILE_TYPE; } break; } /* check link content */ localFileName = String_new(); error = File_readLink(linkName,localFileName); if (error != ERROR_NONE) { printError("Cannot not read local file '%s' (error: %s)!\n", String_cString(linkName), Errors_getText(error) ); String_delete(localFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } if (!String_equals(fileName,localFileName)) { printInfo(2,"FAIL!\n"); printError("Link '%s' does not contain file '%s'!\n", String_cString(linkName), String_cString(fileName) ); String_delete(localFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILES_DIFFER; } break; } String_delete(localFileName); #if 0 /* get local file info */ error = File_getFileInfo(linkName,&localFileInfo); if (error != ERROR_NONE) { printError("Cannot not read local file '%s' (error: %s)!\n", String_cString(linkName), Errors_getText(error) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (failError == ERROR_NONE) failError = error; break; } /* check file time, permissions, file owner/group */ #endif /* 0 */ printInfo(2,"ok\n"); /* free resources */ } else { /* skip */ printInfo(3," Compare '%s'...skipped\n",String_cString(linkName)); } /* close archive file */ Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); } break; case ARCHIVE_ENTRY_TYPE_SPECIAL: { String fileName; FileInfo fileInfo; FileInfo localFileInfo; /* read special */ fileName = String_new(); error = Archive_readSpecialEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, fileName, &fileInfo ); if (error != ERROR_NONE) { printError("Cannot not read 'special' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(fileName); if (failError == ERROR_NONE) failError = error; break; } if ( (List_empty(includeEntryList) || EntryList_match(includeEntryList,fileName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT) ) { printInfo(2," Compare special device '%s'...",String_cString(fileName)); /* check special device */ if (!File_exists(fileName)) { printInfo(2,"FAIL!\n"); printError("Special device '%s' does not exists!\n", String_cString(fileName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_FILE_NOT_FOUND; } break; } if (File_getType(fileName) != FILE_TYPE_SPECIAL) { printInfo(2,"FAIL!\n"); printError("'%s' is not a special device!\n", String_cString(fileName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = ERROR_WRONG_FILE_TYPE; } break; } /* check special settings */ error = File_getFileInfo(fileName,&localFileInfo); if (error != ERROR_NONE) { printError("Cannot not read local file '%s' (error: %s)!\n", String_cString(fileName), Errors_getText(error) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } if (fileInfo.specialType != localFileInfo.specialType) { printError("Different types of special device '%s'!\n", String_cString(fileName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } if ( (fileInfo.specialType == FILE_SPECIAL_TYPE_CHARACTER_DEVICE) || (fileInfo.specialType == FILE_SPECIAL_TYPE_BLOCK_DEVICE) ) { if (fileInfo.major != localFileInfo.major) { printError("Different major numbers of special device '%s'!\n", String_cString(fileName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } if (fileInfo.minor != localFileInfo.minor) { printError("Different minor numbers of special device '%s'!\n", String_cString(fileName) ); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { failError = error; } break; } } #if 0 /* check file time, permissions, file owner/group */ #endif /* 0 */ printInfo(2,"ok\n"); /* free resources */ } else { /* skip */ printInfo(3," Compare '%s'...skipped\n",String_cString(fileName)); } /* close archive file */ Archive_closeEntry(&archiveFileInfo); String_delete(fileName); } break; default: #ifndef NDEBUG HALT_INTERNAL_ERROR_UNHANDLED_SWITCH_CASE(); #endif /* NDEBUG */ break; /* not reached */ } } /* close archive */ Archive_close(&archiveInfo); } /* check fragment lists */ for (fragmentNode = fragmentList.head; fragmentNode != NULL; fragmentNode = fragmentNode->next) { if (!FragmentList_checkEntryComplete(fragmentNode)) { printInfo(0,"Warning: incomplete entry '%s'\n",String_cString(fragmentNode->name)); if (failError == ERROR_NONE) failError = ERROR_FILE_INCOMPLETE; } } /* free resources */ String_delete(archiveFileName); FragmentList_done(&fragmentList); free(buffer); free(archiveBuffer); return failError; }
Errors Command_restore(StringList *archiveFileNameList, PatternList *includePatternList, PatternList *excludePatternList, JobOptions *jobOptions, ArchiveGetCryptPasswordFunction archiveGetCryptPasswordFunction, void *archiveGetCryptPasswordUserData, RestoreStatusInfoFunction restoreStatusInfoFunction, void *restoreStatusInfoUserData, bool *pauseFlag, bool *requestedAbortFlag ) { RestoreInfo restoreInfo; byte *buffer; FileFragmentList fileFragmentList; String archiveFileName; Errors error; ArchiveInfo archiveInfo; ArchiveFileInfo archiveFileInfo; FileTypes fileType; FileFragmentNode *fileFragmentNode; assert(archiveFileNameList != NULL); assert(includePatternList != NULL); assert(excludePatternList != NULL); assert(jobOptions != NULL); /* initialize variables */ restoreInfo.includePatternList = includePatternList; restoreInfo.excludePatternList = excludePatternList; restoreInfo.jobOptions = jobOptions; restoreInfo.pauseFlag = pauseFlag; restoreInfo.requestedAbortFlag = requestedAbortFlag; restoreInfo.error = ERROR_NONE; restoreInfo.statusInfoFunction = restoreStatusInfoFunction; restoreInfo.statusInfoUserData = restoreStatusInfoUserData; restoreInfo.statusInfo.doneFiles = 0L; restoreInfo.statusInfo.doneBytes = 0LL; restoreInfo.statusInfo.skippedFiles = 0L; restoreInfo.statusInfo.skippedBytes = 0LL; restoreInfo.statusInfo.errorFiles = 0L; restoreInfo.statusInfo.errorBytes = 0LL; restoreInfo.statusInfo.fileName = String_new(); restoreInfo.statusInfo.fileDoneBytes = 0LL; restoreInfo.statusInfo.fileTotalBytes = 0LL; restoreInfo.statusInfo.storageName = String_new(); restoreInfo.statusInfo.storageDoneBytes = 0LL; restoreInfo.statusInfo.storageTotalBytes = 0LL; /* allocate resources */ buffer = malloc(BUFFER_SIZE); if (buffer == NULL) { HALT_INSUFFICIENT_MEMORY(); } FileFragmentList_init(&fileFragmentList); archiveFileName = String_new(); while ( ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag)) && !StringList_empty(archiveFileNameList) && (restoreInfo.error == ERROR_NONE) ) { /* pause */ while ((restoreInfo.pauseFlag != NULL) && (*restoreInfo.pauseFlag)) { Misc_udelay(500*1000); } StringList_getFirst(archiveFileNameList,archiveFileName); printInfo(0,"Restore archive '%s':\n",String_cString(archiveFileName)); /* open archive */ error = Archive_open(&archiveInfo, archiveFileName, jobOptions, archiveGetCryptPasswordFunction, archiveGetCryptPasswordUserData ); if (error != ERROR_NONE) { printError("Cannot open archive file '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; continue; } String_set(restoreInfo.statusInfo.storageName,archiveFileName); updateStatusInfo(&restoreInfo); /* read files */ while ( ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag)) && !Archive_eof(&archiveInfo) && (restoreInfo.error == ERROR_NONE) ) { /* pause */ while ((restoreInfo.pauseFlag != NULL) && (*restoreInfo.pauseFlag)) { Misc_udelay(500*1000); } /* get next file type */ error = Archive_getNextFileType(&archiveInfo, &archiveFileInfo, &fileType ); if (error != ERROR_NONE) { printError("Cannot not read next entry in archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; break; } switch (fileType) { case FILE_TYPE_FILE: { String fileName; FileInfo fileInfo; uint64 fragmentOffset,fragmentSize; FileFragmentNode *fileFragmentNode; String destinationFileName; String directoryName; // FileInfo localFileInfo; FileHandle fileHandle; uint64 length; ulong n; /* read file */ fileName = String_new(); error = Archive_readFileEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, NULL, fileName, &fileInfo, &fragmentOffset, &fragmentSize ); if (error != ERROR_NONE) { printError("Cannot not read 'file' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(fileName); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; continue; } if ( (List_empty(includePatternList) || PatternList_match(includePatternList,fileName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT) ) { String_set(restoreInfo.statusInfo.fileName,fileName); restoreInfo.statusInfo.fileDoneBytes = 0LL; restoreInfo.statusInfo.fileTotalBytes = fragmentSize; updateStatusInfo(&restoreInfo); /* get destination filename */ destinationFileName = getDestinationFileName(String_new(), fileName, jobOptions->directory, jobOptions->directoryStripCount ); /* check if file fragment exists */ fileFragmentNode = FileFragmentList_findFile(&fileFragmentList,fileName); if (fileFragmentNode != NULL) { if (!jobOptions->overwriteFilesFlag && FileFragmentList_checkExists(fileFragmentNode,fragmentOffset,fragmentSize)) { printInfo(1," Restore file '%s'...skipped (file part %ll..%ll exists)\n", String_cString(destinationFileName), fragmentOffset, (fragmentSize > 0)?fragmentOffset+fragmentSize-1:fragmentOffset ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); continue; } } else { if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName)) { printInfo(1," Restore file '%s'...skipped (file exists)\n",String_cString(destinationFileName)); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); continue; } fileFragmentNode = FileFragmentList_addFile(&fileFragmentList,fileName,fileInfo.size); } printInfo(2," Restore file '%s'...",String_cString(destinationFileName)); /* create directory if not existing */ directoryName = File_getFilePathName(String_new(),destinationFileName); if (!File_exists(directoryName)) { /* create directory */ error = File_makeDirectory(directoryName, FILE_DEFAULT_USER_ID, FILE_DEFAULT_GROUP_ID, fileInfo.permission ); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot create directory '%s' (error: %s)\n", String_cString(directoryName), Errors_getText(error) ); String_delete(directoryName); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; continue; } /* set owner ship */ error = File_setOwner(directoryName, (jobOptions->owner.userId != FILE_DEFAULT_USER_ID )?jobOptions->owner.userId:fileInfo.userId, (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID)?jobOptions->owner.groupId:fileInfo.groupId ); if (error != ERROR_NONE) { if (jobOptions->stopOnErrorFlag) { printInfo(2,"FAIL!\n"); printError("Cannot set owner ship of directory '%s' (error: %s)\n", String_cString(directoryName), Errors_getText(error) ); String_delete(directoryName); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; continue; } else { printWarning("Cannot set owner ship of directory '%s' (error: %s)\n", String_cString(directoryName), Errors_getText(error) ); } } } String_delete(directoryName); /* write file data */ //if (fileFragmentNode == NULL) File_delete(destinationFileName,TRUE); error = File_open(&fileHandle,destinationFileName,FILE_OPENMODE_WRITE); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot create/write to file '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } error = File_seek(&fileHandle,fragmentOffset); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot write file '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); File_close(&fileHandle); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } length = 0; while ( ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag)) && (length < fragmentSize) ) { /* pause */ while ((restoreInfo.pauseFlag != NULL) && (*restoreInfo.pauseFlag)) { Misc_udelay(500*1000); } n = MIN(fragmentSize-length,BUFFER_SIZE); error = Archive_readFileData(&archiveFileInfo,buffer,n); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot not read content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; break; } error = File_write(&fileHandle,buffer,n); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot write file '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } break; } restoreInfo.statusInfo.fileDoneBytes += n; updateStatusInfo(&restoreInfo); length += n; } if (File_getSize(&fileHandle) > fileInfo.size) { File_truncate(&fileHandle,fileInfo.size); } File_close(&fileHandle); if ((restoreInfo.requestedAbortFlag != NULL) && (*restoreInfo.requestedAbortFlag)) { printInfo(2,"ABORTED\n"); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); continue; } #if 0 if (restoreInfo.error != ERROR_NONE) { String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); continue; } #endif /* 0 */ /* set file time, file owner/group */ if (jobOptions->owner.userId != FILE_DEFAULT_USER_ID ) fileInfo.userId = jobOptions->owner.userId; if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId; error = File_setFileInfo(destinationFileName,&fileInfo); if (error != ERROR_NONE) { if (jobOptions->stopOnErrorFlag) { printInfo(2,"FAIL!\n"); printError("Cannot set file info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); restoreInfo.error = error; continue; } else { printWarning("Cannot set file info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); } } /* add fragment to file fragment list */ FileFragmentList_add(fileFragmentNode,fragmentOffset,fragmentSize); //FileFragmentList_print(fileFragmentNode,String_cString(fileName)); /* discard fragment list if file is complete */ if (FileFragmentList_checkComplete(fileFragmentNode)) { FileFragmentList_removeFile(&fileFragmentList,fileFragmentNode); } /* free resources */ String_delete(destinationFileName); printInfo(2,"ok\n"); } else { /* skip */ printInfo(3," Restore '%s'...skipped\n",String_cString(fileName)); } /* close archive file, free resources */ Archive_closeEntry(&archiveFileInfo); String_delete(fileName); } break; case FILE_TYPE_DIRECTORY: { String directoryName; FileInfo fileInfo; String destinationFileName; // FileInfo localFileInfo; /* read directory */ directoryName = String_new(); error = Archive_readDirectoryEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, directoryName, &fileInfo ); if (error != ERROR_NONE) { printError("Cannot not read 'directory' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(directoryName); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; break; } if ( (List_empty(includePatternList) || PatternList_match(includePatternList,directoryName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,directoryName,PATTERN_MATCH_MODE_EXACT) ) { String_set(restoreInfo.statusInfo.fileName,directoryName); restoreInfo.statusInfo.fileDoneBytes = 0LL; restoreInfo.statusInfo.fileTotalBytes = 00L; updateStatusInfo(&restoreInfo); /* get destination filename */ destinationFileName = getDestinationFileName(String_new(), directoryName, jobOptions->directory, jobOptions->directoryStripCount ); /* check if directory already exists */ if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName)) { printInfo(1, " Restore directory '%s'...skipped (file exists)\n", String_cString(destinationFileName) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); continue; } printInfo(2," Restore directory '%s'...",String_cString(destinationFileName)); /* create directory */ error = File_makeDirectory(destinationFileName, FILE_DEFAULT_USER_ID, FILE_DEFAULT_GROUP_ID, fileInfo.permission ); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot create directory '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } /* set file time, file owner/group */ if (jobOptions->owner.userId != FILE_DEFAULT_USER_ID ) fileInfo.userId = jobOptions->owner.userId; if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId; error = File_setFileInfo(destinationFileName,&fileInfo); if (error != ERROR_NONE) { if (jobOptions->stopOnErrorFlag) { printInfo(2,"FAIL!\n"); printError("Cannot set directory info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } else { printWarning("Cannot set directory info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); } } /* free resources */ String_delete(destinationFileName); printInfo(2,"ok\n"); } else { /* skip */ printInfo(3," Restore '%s'...skipped\n",String_cString(directoryName)); } /* close archive file */ Archive_closeEntry(&archiveFileInfo); String_delete(directoryName); } break; case FILE_TYPE_LINK: { String linkName; String fileName; FileInfo fileInfo; String destinationFileName; // FileInfo localFileInfo; /* read link */ linkName = String_new(); fileName = String_new(); error = Archive_readLinkEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, linkName, fileName, &fileInfo ); if (error != ERROR_NONE) { printError("Cannot not read 'link' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(fileName); String_delete(linkName); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; break; } if ( (List_empty(includePatternList) || PatternList_match(includePatternList,linkName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,linkName,PATTERN_MATCH_MODE_EXACT) ) { String_set(restoreInfo.statusInfo.fileName,linkName); restoreInfo.statusInfo.fileDoneBytes = 0LL; restoreInfo.statusInfo.fileTotalBytes = 00L; updateStatusInfo(&restoreInfo); /* get destination filename */ destinationFileName = getDestinationFileName(String_new(), linkName, jobOptions->directory, jobOptions->directoryStripCount ); /* create link */ if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName)) { printInfo(1, " Restore link '%s'...skipped (file exists)\n", String_cString(destinationFileName) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = ERROR_FILE_EXITS; } continue; } printInfo(2," Restore link '%s'...",String_cString(destinationFileName)); error = File_makeLink(destinationFileName,fileName); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot create link '%s' -> '%s' (error: %s)\n", String_cString(destinationFileName), String_cString(fileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } /* set file time, file owner/group */ if (jobOptions->owner.userId != FILE_DEFAULT_USER_ID ) fileInfo.userId = jobOptions->owner.userId; if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId; error = File_setFileInfo(destinationFileName,&fileInfo); if (error != ERROR_NONE) { if (jobOptions->stopOnErrorFlag) { printInfo(2,"FAIL!\n"); printError("Cannot set file info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } else { printWarning("Cannot set file info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); } } /* free resources */ String_delete(destinationFileName); printInfo(2,"ok\n"); } else { /* skip */ printInfo(3," Restore '%s'...skipped\n",String_cString(linkName)); } /* close archive file */ Archive_closeEntry(&archiveFileInfo); String_delete(fileName); String_delete(linkName); } break; case FILE_TYPE_SPECIAL: { String fileName; FileInfo fileInfo; String destinationFileName; // FileInfo localFileInfo; /* read special device */ fileName = String_new(); error = Archive_readSpecialEntry(&archiveInfo, &archiveFileInfo, NULL, NULL, fileName, &fileInfo ); if (error != ERROR_NONE) { printError("Cannot not read 'special' content of archive '%s' (error: %s)!\n", String_cString(archiveFileName), Errors_getText(error) ); String_delete(fileName); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = error; break; } if ( (List_empty(includePatternList) || PatternList_match(includePatternList,fileName,PATTERN_MATCH_MODE_EXACT)) && !PatternList_match(excludePatternList,fileName,PATTERN_MATCH_MODE_EXACT) ) { String_set(restoreInfo.statusInfo.fileName,fileName); restoreInfo.statusInfo.fileDoneBytes = 0LL; restoreInfo.statusInfo.fileTotalBytes = 00L; updateStatusInfo(&restoreInfo); /* get destination filename */ destinationFileName = getDestinationFileName(String_new(), fileName, jobOptions->directory, jobOptions->directoryStripCount ); /* create special device */ if (!jobOptions->overwriteFilesFlag && File_exists(destinationFileName)) { printInfo(1, " Restore special device '%s'...skipped (file exists)\n", String_cString(destinationFileName) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = ERROR_FILE_EXITS; } continue; } printInfo(2," Restore special device '%s'...",String_cString(destinationFileName)); error = File_makeSpecial(destinationFileName, fileInfo.specialType, fileInfo.major, fileInfo.minor ); if (error != ERROR_NONE) { printInfo(2,"FAIL!\n"); printError("Cannot create special device '%s' (error: %s)\n", String_cString(fileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } /* set file time, file owner/group */ if (jobOptions->owner.userId != FILE_DEFAULT_USER_ID ) fileInfo.userId = jobOptions->owner.userId; if (jobOptions->owner.groupId != FILE_DEFAULT_GROUP_ID) fileInfo.groupId = jobOptions->owner.groupId; error = File_setFileInfo(destinationFileName,&fileInfo); if (error != ERROR_NONE) { if (jobOptions->stopOnErrorFlag) { printInfo(2,"FAIL!\n"); printError("Cannot set file info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); String_delete(destinationFileName); Archive_closeEntry(&archiveFileInfo); String_delete(fileName); if (jobOptions->stopOnErrorFlag) { restoreInfo.error = error; } continue; } else { printWarning("Cannot set file info of '%s' (error: %s)\n", String_cString(destinationFileName), Errors_getText(error) ); } } /* free resources */ String_delete(destinationFileName); printInfo(2,"ok\n"); } else { /* skip */ printInfo(3," Restore '%s'...skipped\n",String_cString(fileName)); } /* close archive file */ Archive_closeEntry(&archiveFileInfo); String_delete(fileName); } break; default: #ifndef NDEBUG HALT_INTERNAL_ERROR_UNHANDLED_SWITCH_CASE(); #endif /* NDEBUG */ break; /* not reached */ } } /* close archive */ Archive_close(&archiveInfo); } /* check fragment lists */ if ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag)) { for (fileFragmentNode = fileFragmentList.head; fileFragmentNode != NULL; fileFragmentNode = fileFragmentNode->next) { if (!FileFragmentList_checkComplete(fileFragmentNode)) { printInfo(0,"Warning: incomplete file '%s'\n",String_cString(fileFragmentNode->fileName)); if (restoreInfo.error == ERROR_NONE) restoreInfo.error = ERROR_FILE_INCOMPLETE; } } } /* free resources */ String_delete(archiveFileName); FileFragmentList_done(&fileFragmentList); free(buffer); String_delete(restoreInfo.statusInfo.fileName); String_delete(restoreInfo.statusInfo.storageName); if ((restoreInfo.requestedAbortFlag == NULL) || !(*restoreInfo.requestedAbortFlag)) { return restoreInfo.error; } else { return ERROR_ABORTED; } }