Errors File_printLine(FileHandle *fileHandle, const char *format, ... ) { String line; va_list arguments; Errors error; assert(fileHandle != NULL); assert(fileHandle->file != NULL); assert(format != NULL); /* initialise variables */ line = String_new(); /* format line */ va_start(arguments,format); String_vformat(line,format,arguments); va_end(arguments); /* write line */ error = File_write(fileHandle,String_cString(line),String_length(line)); if (error != ERROR_NONE) { String_delete(line); return error; } error = File_write(fileHandle,"\n",1); if (error != ERROR_NONE) { String_delete(line); return error; } /* free resources */ String_delete(line); return ERROR_NONE; }
Errors File_writeLine(FileHandle *fileHandle, const String line ) { Errors error; assert(fileHandle != NULL); assert(fileHandle->file != NULL); assert(line != NULL); error = File_write(fileHandle,String_cString(line),String_length(line)); if (error != ERROR_NONE) { return error; } error = File_write(fileHandle,"\n",1); if (error != ERROR_NONE) { return error; } return ERROR_NONE; }
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; }
/************************************************************************ void Open_desk(pList pTable) 开桌 ************************************************************************/ void Open_desk(pList pTable) { pList pt; int n; struct Table_t *ps; char str[8] = {0}; FILE *fp; fp = File_open("./Date/Table.txt"); while (1) { system("cls"); n = Table_search(pTable,0,3);// 打印空闲和预定的台桌 if (n == 0) { printf(",暂无空闲桌子,按任意键返回..."); getch(); return; } printf("请输入要开桌的台桌号:"); glb_putString(str,'0','9',3,2);// str存放要开桌的台桌号 pt = pTable->pNext; while(pt != NULL) { ps = (struct Table_t *)(pt->pData); if (strcmp(ps->acNo,str) == 0) { if ((ps->state == 0)||(ps->state == 3)) break; } pt = pt->pNext; } if (pt == NULL) { memset(str,0,sizeof(char)); printf("\n台桌号有误或不可用,请重新输入,按任意键继续..."); getch(); } else break; } if (ps->state == 3)// 若为预定状态,直接跳转为点菜界面 { ps->state = 2;//占用,转到点菜界面 File_write(fp,pTable,sizeof(struct Table_t),0);// 更新台桌文件 printf("\n开桌成功,按任意键继续..."); getch(); Order_dishes(pTable);// 跳转到点菜界面 return; } printf("\n是否马上开始点菜(y)确定、(n)返回:"); if(glb_putString(NULL,0,0,1,1) != 'y') { ps->state = 3;//预定状态 File_write(fp,pTable,sizeof(struct Table_t),0); printf("\n预定成功,按任意键继续..."); getch(); } else { ps->state = 2;//占用,转到点菜界面 File_write(fp,pTable,sizeof(struct Table_t),0); printf("\n开桌成功,按任意键继续..."); getch(); Order_dishes(pTable); return; } }
/************************************************************************ void Settle_Accounts(pList pTable) 结账功能 ************************************************************************/ void Settle_Accounts(pList pTable) { FILE *fp; int money; pList pt,pTitle,pOrder,ps; struct Order_t * data; char txt[] = ".txt"; char str[6] = {0}; char str1[6] = {0}; char tabpath[30] ="./Date/Cache/";// 未结详单路径 fp = File_open("./Date/Cache/Order.txt");// 打开未买订单文件 pOrder = File_read(fp,sizeof(struct Order_t)); while(1) { system("cls"); pt = pOrder->pNext; if (pt == NULL)//判断当前是否有未买订单 { printf("\n目前没有未买订单,按任意键返回..."); return; } printf("\t\t%12s%12s%11s%11s\n","订单号","台桌号","金额","状态"); while (pt) { data = (struct Order_t *)(pt->pData); printf("\t\t%12s%12s%11d%11s\n",data->ordernum,data->tablenum,data->money,"未支付");// 打印所有未结订单信息 pt = pt->pNext; } printf("\n请输入要结账的台桌号(3位):"); glb_putString(str,'0','9',3,2); ps = pOrder; pt = pOrder->pNext; while (pt) { data = (struct Order_t *)(pt->pData); if (strcmp(data->tablenum,str) == 0)// 找出要结账的订单结点 break; ps = pt; pt = pt->pNext; } if (pt == NULL)// 未找到订单,作提示 { printf("\n\n台桌号无订单或有误,按<Esc>键返回、其他键重新输入:"); if (getch() == 27) return; memset(str,0,sizeof(char)); } else break; } strcat(tabpath,str);// 获取详单的路径 strcat(tabpath,txt); fp = File_open(tabpath);// 打开将结账的详单文件 pTitle = File_read(fp,sizeof(struct Title_t));// 读出未买详单链表 Title_print(pTitle,data);// 打印未买详单信息 printf("\n订单号为%s是否结账,(y)确定、(n)返回:",data->ordernum); if (glb_putString(NULL,0,0,1,1) == 'y') { printf("\n实收金额:"); money = glb_putString(str1,'0','9',5,2);// 输入金额 if (money < data->money)// 实收金额不可小于订单金额 { printf("\n实收金额小于订单金额,无法结账,按任意键返回..."); getch(); return; } printf("\n回找金额:%d",money - (data->money)); fp = File_open("./Date/Title/Title.txt"); File_write(fp,pTitle,sizeof(struct Title_t),2);//写入已结详单链表 fp = File_open("./Date/Order/Order.txt"); fseek(fp,0,2); strcpy(data->acname,acName);//写入结账服务员登录名到订单结构体中 fwrite(data,sizeof(struct Order_t),1,fp);//写入已结订单的结点到另一个文件 fflush(fp); ps->pNext = pt->pNext;// 删除结点 free(pt);//释放已结订单的结点 fp = fopen("./Date/Cache/Order.txt","w+"); File_write(fp,pOrder,sizeof(struct Order_t),0);//刷新未结订单的文件 pt = pTable->pNext; while(pt) { if(strcmp(((struct Table_t *)(pt->pData))->acNo,str) == 0)// 找到已结账台桌结点 { ((struct Table_t *)(pt->pData))->state = 0;// 桌子状态改为空闲 fp = File_open("./Date/Table.txt"); File_write(fp,pTable,sizeof(struct Table_t),0);// 更新台桌信息文件 break; } pt = pt->pNext; } printf("\n结账成功"); } else printf("\n结账失败"); printf(",按任意键返回..."); getch(); List_free(pTitle); List_free(pOrder); }
/************************************************************************ void Order_dishes(pList pTable) 点菜 ************************************************************************/ void Order_dishes(pList pTable) { FILE *fd; int n,count1; pList pMenu,pOrder,pTitle,pt; struct Order_t *pNew,*pdata; char txt[] = ".txt"; char str[8] = {0}; char tabpath[30] ="./Date/Cache/";// 详单的相对路径 fd = File_open("./Date/Menu.txt"); pMenu = File_read(fd,sizeof(struct Menu_t)); fd = File_open("./Date/Cache/Order.txt"); pOrder = File_read(fd,sizeof(struct Order_t)); while (1) { system("cls"); n = Table_search(pTable,2,4);// 判断是否有可用桌子 if (n == 0) { printf(",暂无可用桌子,按任意键继续..."); getch(); return; } printf("请输入要点菜的台桌号:"); glb_putString(str,'0','9',3,2); strcat(tabpath,str); strcat(tabpath,txt);// 获取详单的路径 pt = pOrder->pNext; while(pt) { pdata = (struct Order_t *)(pt->pData); if (strcmp(pdata->tablenum,str) == 0)// 判断当前未买订单中是否存在此台桌的订单 { pNew = pdata; fd = File_open(tabpath); pTitle = File_read(fd,sizeof(struct Title_t)); break; } pt = pt->pNext; } if (pt == NULL)// 未买订单不存在输入台桌的订单 { pt = pTable ->pNext; while(pt) { if (strcmp(((struct Table_t *)(pt->pData))->acNo,str) == 0) { if (((struct Table_t *)(pt->pData))->state == 2) { pNew = Order_init(str);// 初始化一个订单结点 List_add(pOrder,pNew); File_write(fd,pOrder,sizeof(struct Order_t),0);// 写入未买订单文件 fd = fopen(tabpath,"w+");// 已w+方式打开详单文件,便于开始点菜 pTitle = File_read(fd,sizeof(struct Title_t)); break; } else if (((struct Table_t *)(pt->pData))->state == 0) { printf("\n此桌号为空闲需先开桌才能点菜,是否开桌,(y)开桌、(n)返回:"); if (glb_putString(NULL,0,0,1,1) == 'y') Open_desk(pTable);// 跳转到开桌界面 return; } } pt = pt->pNext; } if (pt == NULL) { memset(str,0,sizeof(char)); strcpy(tabpath,"./Date/Cache/"); printf("\n输入的桌号有误或者处于维修状态,请重新输入,按任意键继续..."); getch(); } else break; } else break; } Order_print(pMenu,pTitle,pNew); count1 = List_count(pMenu);// 获取菜谱的个数 while (1) { JR_EmptyRaw(count1+3,count1+12);// 清空菜谱下面的几行信息 JR_SetCursor(count1+3,0); printf("\t\t(1):点菜\n"); printf("\t\t(2):退菜\n"); printf("\t\t(3):返回\n"); printf("\t\t请输入要操作的功能:"); n = glb_putString(NULL,'1','3',1,2); switch(n) { case 1: { Order_add(count1,pNew,pTitle,pOrder,pMenu,tabpath); // 加菜功能函数 break; } case 2: { Order_del(count1,pNew,pTitle,pMenu,pOrder,tabpath);// 减菜功能函数 break; } case 3: break; } if (n == 3) { break; } } List_free(pOrder); List_free(pMenu); List_free(pTitle); }
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; } }