📄 pack.c
字号:
(char *) time_t_to_intstr(statb.st_mtime, mtimestr), (int) statb.st_uid, (int) statb.st_gid, (int) strlen(name), name); ER__(ofunc(sbuf, strlen(sbuf), params), i); if(!params->dont_keep_atime) utime(name, &utim); if(params->verbose && params->verbosefunc){ sprintf(verbosestr, "%s\n", esc_name); params->verbosefunc(verbosestr, params); } } else if(IS_BLOCKDEV(statb)){ sprintf(sbuf, "%d;%lu;%s;%d;%d;%lu;%d;%s.", BLOCKDEVICE | ftype_attrs, (unsigned long) statb.st_mode, (char *) time_t_to_intstr(statb.st_mtime, mtimestr), (int) statb.st_uid, (int) statb.st_gid, (unsigned long) statb.st_rdev, (int) strlen(name), name); ER__(ofunc(sbuf, strlen(sbuf), params), i); if(!params->dont_keep_atime) utime(name, &utim); if(params->verbose && params->verbosefunc){ sprintf(verbosestr, "%s\n", esc_name); params->verbosefunc(verbosestr, params); } } else if(IS_CHARDEV(statb)){ sprintf(sbuf, "%d;%lu;%s;%d;%d;%lu;%d;%s.", CHARDEVICE | ftype_attrs, (unsigned long) statb.st_mode, (char *) time_t_to_intstr(statb.st_mtime, mtimestr), (int) statb.st_uid, (int) statb.st_gid, (unsigned long) statb.st_rdev, (int) strlen(name), name); ER__(ofunc(sbuf, strlen(sbuf), params), i); if(!params->dont_keep_atime) utime(name, &utim); if(params->verbose && params->verbosefunc){ sprintf(verbosestr, "%s\n", esc_name); params->verbosefunc(verbosestr, params); } } else if(IS_REGFILE(statb)){ Flag compression_done, dont_compress; dont_compress = NO; if(params->dont_compress){ UChar **cpptr; for(cpptr = params->dont_compress; *cpptr; cpptr++){ if(!fn_match(*cpptr, FN_BASENAME(name), 0)){ dont_compress = YES; break; } } } params->vars.sum_filesizes += (Real64) statb.st_size; compress = ((unzipcmd[0]#ifdef USE_ZLIB || params->bi_compr_level > 0#endif ) && statb.st_size > 0 && (!dont_compress)); if(! compress){ ER__(write_file_uncompressed(name, &statb, params, ftype_attrs), i); } else{ UChar compressbuf[0x1000 + 2]; compression_done = NO; fd = pid = -1; i = access(name, R_OK); if(! i) i = open_for_compress(&fd, name, params->zipcmd, &pid, params); if(!i){ n = strlen(unzipcmd); cptr = ""; if(params->bi_compr_level > 0){ if(n > 0){ n++; cptr = ". "; } else{ cptr = "."; } n++; cks = NO; /* built-in compression already does checksumming */ } ftype = REGFILE;#ifdef USE_ZLIB if(cks){ ftype = REGFILECKS; crc32sum = crc32(0L, Z_NULL, 0); }#endif sprintf(sbuf, "%d;%lu;%s;%d;%d;%d;%s;%d;", ftype | ftype_attrs, (unsigned long) statb.st_mode, (char *) time_t_to_intstr(statb.st_mtime, mtimestr), (int) statb.st_uid, (int) statb.st_gid, (int) strlen(name), name, (int) n); ER__(ofunc(sbuf, strlen(sbuf), params), i); sprintf(sbuf, "%s%s;%d;", cptr, unzipcmd, 0); ER__(ofunc(sbuf, strlen(sbuf), params), i); compression_done = YES; do{ n = read_file(fd, compressbuf + 2, 0xfff, ¶ms->vars.zfile, readfunc); if(n < 0){ fprintf(params->errfp, T_("Error: Fault during read of compressed file `%s'.\n"), name); params->vars.errnum |= EPACKCOMPR; n = 0; compression_done = NO; }#ifdef USE_ZLIB if(cks && n > 0) crc32sum = crc32(crc32sum, compressbuf + 2, n);#endif UnsN_to_xref(compressbuf, n, 16); ER__(ofunc(compressbuf, n + 2, params), i); params->vars.sum_compr_filesizes += (Real64) (n + 2); } while(n == 0xfff); pst = 0; if(pid > 0){ waitpid_forced(pid, &pst, 0); if( (i = WEXITSTATUS(pst)) ){ fprintf(params->errfp, T_("Error: Compression program returned bad status %d for `%s'.\n"), (int) i, name); params->vars.errnum |= EPACKCOMPR; compression_done = NO; buf[0] = '.'; /* terminate the data stream correctly for */ ER__(ofunc(buf, 1, params), i); /* the attempt to write */ } /* not compressed */ } close(fd);#ifdef USE_ZLIB close_file_zip(¶ms->vars.zfile); if(cks){ Uns32_to_xref(compressbuf, crc32sum); ER__(ofunc(compressbuf, 4, params), i); }#endif } else{ if(fd >= 0){ close(fd); } if(pid > 0){ kill(pid, SIGTERM); waitpid_forced(pid, &pst, 0); } } if(!compression_done){ ER__(write_file_uncompressed(name, &statb, params, ftype_attrs), i); } } buf[0] = '.'; ER__(ofunc(buf, 1, params), i); if(!params->dont_keep_atime) utime(name, &utim); if(params->verbose && params->verbosefunc){ sprintf(verbosestr, "%s\n", esc_name); params->verbosefunc(verbosestr, params); } }#ifdef IS_DOOR else if(IS_DOOR(statb)) { /* * This is a file special to the OS which will be created on demand. * Don't try to archive it, and don't throw any errors/warnings. */ ; } #endif else{ fprintf(errfp, T_("Error: `%s' is an illegal type of file.\n"), name); params->vars.errnum |= EPACKTYPE; return(0 /* WARNING */); } return(0);}Int32pack_writeout(UChar * name, AarParams * params, Int16 endofrecord){ Int32 i; UChar buf[30]; i = 0; if(name) i = l_writeout(name, params, NO); if(endofrecord){ sprintf(buf, "%d;", ENDOFARCHIVE); i = params->outputfunc(buf, strlen(buf), params); } return(i);}Int32pack_default_output(UChar * buffer, Int32 num, AarParams * params){ return(write_forced(params->outfd, buffer, num));}static Int32write_filecont( UChar *name, struct stat *statb, AarParams *params, Flag compress, int ftype_attrs){ int fd, pid, pst; Int32 i, num_read, n, ret = 0; UChar sbuf[MAXPATHLEN * 2 + 200], mtimestr[50]; UChar buf[256]; UChar *unzipcmd, *cptr; FILE *errfp; Uns32 readerrno; Int32 (*ofunc)(UChar *, Int32, AarParams *); Int32 (*readfunc)(int, UChar *, Int32); int ftype; Flag cks; Uns32 crc32sum; /* uninitialized OK */ cks = NO; ftype = FILECONTENTS;#ifdef USE_ZLIB cks = params->check; if(params->bi_compr_level > 0) cks = NO; /* built-in compression already does checksumming */ if(cks){ ftype = FILECONTENTSCKS; crc32sum = crc32(0L, Z_NULL, 0); }#endif ftype |= ftype_attrs; unzipcmd = ""; ofunc = params->outputfunc; errfp = params->errfp; readfunc = params->readfunc; fd = -1; pid = -1; readerrno = EPACKREAD; if(params->zipcmd && params->unzipcmd) if(*params->zipcmd && *params->unzipcmd) unzipcmd = params->unzipcmd; compress = (compress && (unzipcmd[0]#ifdef USE_ZLIB || params->bi_compr_level > 0#endif )); if(compress){ i = open_for_compress(&fd, name, params->zipcmd, &pid, params); readerrno |= EPACKCOMPR; } else{ fd = open_for_pack(name, O_RDONLY | O_BINARY); i = (fd < 0 ? -1 : 0); unzipcmd = ""; }#ifdef USE_ZLIB params->vars.zfile.fd = fd;#endif if(i){ fprintf(errfp, T_("Error: cannot open file `%s'.\n"), name); params->vars.errnum |= readerrno; return(-ENOENT); } n = strlen(unzipcmd); cptr = ""; if(compress && params->bi_compr_level > 0){ if(n > 0){ n++; cptr = ". "; } else{ cptr = "."; } n++; } sprintf(sbuf, "%d;%s;%d;%s;%d;%s%s;", ftype, (char *) time_t_to_intstr(statb->st_mtime, mtimestr), (int) strlen(name), name, (int) n, cptr, unzipcmd); if( (i = ofunc(sbuf, strlen(sbuf), params)) ){ ret = i; params->vars.errnum |= EPACKWRITE; GETOUT; } do{ num_read = 0; forever{ i = read_file(fd, buf + 1 + num_read, 255 - num_read, ¶ms->vars.zfile, readfunc); if(i > 0){#ifdef USE_ZLIB if(cks) crc32sum = crc32(crc32sum, buf + 1 + num_read, i);#endif num_read += i; } if(i < 0){ fprintf(params->errfp, T_("Error: Unexpected error reading contents of `%s'.\n"), name); params->vars.errnum |= readerrno; } if(i <= 0) break; } buf[0] = (UChar) num_read; /*if(num_read < 255) memset(buf + 1 + num_read, 0, sizeof(UChar) * (255 - num_read));*/ if( (i = ofunc(buf, num_read + 1, params)) ){ ret = i; params->vars.errnum |= EPACKWRITE; GETOUT; } } while(num_read == 255); if(cks) Uns32_to_xref(buf, crc32sum); buf[4] = '.'; i = (cks ? 0 : 4); if( (i = ofunc(buf + i, 1 + 4 - i, params)) ){ ret = i; params->vars.errnum |= EPACKWRITE; GETOUT; } cleanup: if(fd >= 0) close(fd); if(compress && pid >= 0){ waitpid_forced(pid, &pst, 0); ret = WEXITSTATUS(pst); if(ret) params->vars.errnum |= EPACKCOMPR; }#ifdef USE_ZLIB close_file_zip(¶ms->vars.zfile);#endif return(ret); getout: if(pid >= 0) kill(pid, SIGTERM); CLEANUP;}static UChar *packer_errstrs[] = { TN_ ("General error"), TN_ ("Error writing packed data stream"), TN_ ("Error reading data while packing"), TN_ ("Error reading symbolic link while packing"), TN_ ("Error compressing data while packing"), TN_ ("Unknown filesystem entry type found while packing"), TN_ ("Size of file changed while packing it"), TN_ ("Error reading command output while packing"), TN_ ("Error while packing ACLs"), TN_ ("Given filesystem entry not found while packing"), NULL, NULL, NULL, NULL, NULL, NULL, TN_ ("Required built-in uncompress not available"), TN_ ("Error uncompressing data during extract"), TN_ ("Error reading packed data stream during extract"), TN_ ("Format error in packed data stream"), TN_ ("Error creating base directory during extract"), TN_ ("Error setting filesystem entry properties"), TN_ ("Error creating filesystem entry during extract"), TN_ ("Error setting ACLs during extract"), TN_ ("Filesystem entry already exists, must not remove"), TN_ ("Error writing data to file during extract"), TN_ ("Error writing data to command input"), TN_ ("File to write contents to does not exist"), TN_ ("Wrong checksum reading packed data stream"), TN_ ("No writing permission"), NULL, };UChar **packer_strerrors(UChar ** estrs, Uns32 errnum){ Int32 i, j, n; n = sizeof(packer_errstrs) / sizeof(packer_errstrs[0]); if(!estrs){ estrs = NEWP(UChar *, n + 1); if(!estrs) return(NULL); } for(i = j = 0; i < n; i++){ if(errnum & (1 << i)){ if( (estrs[j] = T_(packer_errstrs[i])) ) j++; } } estrs[j] = NULL; return(estrs);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -