diff options
Diffstat (limited to 'contrib/libarchive/cpio/cpio.c')
-rw-r--r-- | contrib/libarchive/cpio/cpio.c | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/contrib/libarchive/cpio/cpio.c b/contrib/libarchive/cpio/cpio.c index fb814a2..4918138 100644 --- a/contrib/libarchive/cpio/cpio.c +++ b/contrib/libarchive/cpio/cpio.c @@ -207,6 +207,9 @@ main(int argc, char *argv[]) case 'B': /* POSIX 1997 */ cpio->bytes_per_block = 5120; break; + case OPTION_B64ENCODE: + cpio->add_filter = opt; + break; case 'C': /* NetBSD/OpenBSD */ cpio->bytes_per_block = atoi(cpio->argument); if (cpio->bytes_per_block <= 0) @@ -234,6 +237,9 @@ main(int argc, char *argv[]) lafe_errc(1, 0, "Error : %s", archive_error_string(cpio->matching)); break; + case OPTION_GRZIP: + cpio->compress = opt; + break; case 'H': /* GNU cpio (also --format) */ cpio->format = cpio->argument; break; @@ -265,7 +271,9 @@ main(int argc, char *argv[]) case 'l': /* POSIX 1997 */ cpio->option_link = 1; break; + case OPTION_LRZIP: case OPTION_LZMA: /* GNU tar, others */ + case OPTION_LZOP: /* GNU tar, others */ cpio->compress = opt; break; case 'm': /* POSIX 1997 */ @@ -326,6 +334,9 @@ main(int argc, char *argv[]) cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; break; + case OPTION_UUENCODE: + cpio->add_filter = opt; + break; case 'v': /* POSIX 1997 */ cpio->verbose++; break; @@ -417,6 +428,7 @@ main(int argc, char *argv[]) archive_match_free(cpio->matching); free_cache(cpio->gname_cache); free_cache(cpio->uname_cache); + free(cpio->destdir); return (cpio->return_value); } @@ -516,27 +528,49 @@ mode_out(struct cpio *cpio) if (cpio->archive == NULL) lafe_errc(1, 0, "Failed to allocate archive object"); switch (cpio->compress) { + case OPTION_GRZIP: + r = archive_write_add_filter_grzip(cpio->archive); + break; case 'J': - r = archive_write_set_compression_xz(cpio->archive); + r = archive_write_add_filter_xz(cpio->archive); + break; + case OPTION_LRZIP: + r = archive_write_add_filter_lrzip(cpio->archive); break; case OPTION_LZMA: - r = archive_write_set_compression_lzma(cpio->archive); + r = archive_write_add_filter_lzma(cpio->archive); + break; + case OPTION_LZOP: + r = archive_write_add_filter_lzop(cpio->archive); break; case 'j': case 'y': - r = archive_write_set_compression_bzip2(cpio->archive); + r = archive_write_add_filter_bzip2(cpio->archive); break; case 'z': - r = archive_write_set_compression_gzip(cpio->archive); + r = archive_write_add_filter_gzip(cpio->archive); break; case 'Z': - r = archive_write_set_compression_compress(cpio->archive); + r = archive_write_add_filter_compress(cpio->archive); break; default: - r = archive_write_set_compression_none(cpio->archive); + r = archive_write_add_filter_none(cpio->archive); break; } if (r < ARCHIVE_WARN) lafe_errc(1, 0, "Requested compression not available"); + switch (cpio->add_filter) { + case 0: + r = ARCHIVE_OK; + break; + case OPTION_B64ENCODE: + r = archive_write_add_filter_b64encode(cpio->archive); + break; + case OPTION_UUENCODE: + r = archive_write_add_filter_uuencode(cpio->archive); + break; + } + if (r < ARCHIVE_WARN) + lafe_errc(1, 0, "Requested filter not available"); r = archive_write_set_format_by_name(cpio->archive, cpio->format); if (r != ARCHIVE_OK) lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); @@ -548,7 +582,7 @@ mode_out(struct cpio *cpio) /* * The main loop: Copy each file into the output archive. */ - r = archive_write_open_file(cpio->archive, cpio->filename); + r = archive_write_open_filename(cpio->archive, cpio->filename); if (r != ARCHIVE_OK) lafe_errc(1, 0, "%s", archive_error_string(cpio->archive)); lr = lafe_line_reader("-", cpio->option_null); @@ -577,7 +611,7 @@ mode_out(struct cpio *cpio) if (!cpio->quiet) { int64_t blocks = - (archive_position_uncompressed(cpio->archive) + 511) + (archive_filter_bytes(cpio->archive, 0) + 511) / 512; fprintf(stderr, "%lu %s\n", (unsigned long)blocks, blocks == 1 ? "block" : "blocks"); @@ -806,18 +840,21 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry) exit(1); if (r >= ARCHIVE_WARN && archive_entry_size(entry) > 0 && fd >= 0) { - bytes_read = read(fd, cpio->buff, cpio->buff_size); + bytes_read = read(fd, cpio->buff, (unsigned)cpio->buff_size); while (bytes_read > 0) { - r = archive_write_data(cpio->archive, + ssize_t bytes_write; + bytes_write = archive_write_data(cpio->archive, cpio->buff, bytes_read); - if (r < 0) + if (bytes_write < 0) lafe_errc(1, archive_errno(cpio->archive), "%s", archive_error_string(cpio->archive)); - if (r < bytes_read) { + if (bytes_write < bytes_read) { lafe_warnc(0, - "Truncated write; file may have grown while being archived."); + "Truncated write; file may have " + "grown while being archived."); } - bytes_read = read(fd, cpio->buff, cpio->buff_size); + bytes_read = read(fd, cpio->buff, + (unsigned)cpio->buff_size); } } @@ -908,7 +945,8 @@ mode_in(struct cpio *cpio) archive_read_support_filter_all(a); archive_read_support_format_all(a); - if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) + if (archive_read_open_filename(a, cpio->filename, + cpio->bytes_per_block)) lafe_errc(1, archive_errno(a), "%s", archive_error_string(a)); for (;;) { @@ -957,7 +995,7 @@ mode_in(struct cpio *cpio) if (r != ARCHIVE_OK) lafe_errc(1, 0, "%s", archive_error_string(ext)); if (!cpio->quiet) { - int64_t blocks = (archive_position_uncompressed(a) + 511) + int64_t blocks = (archive_filter_bytes(a, 0) + 511) / 512; fprintf(stderr, "%lu %s\n", (unsigned long)blocks, blocks == 1 ? "block" : "blocks"); @@ -988,7 +1026,7 @@ extract_data(struct archive *ar, struct archive *aw) "%s", archive_error_string(ar)); exit(1); } - r = archive_write_data_block(aw, block, size, offset); + r = (int)archive_write_data_block(aw, block, size, offset); if (r != ARCHIVE_OK) { lafe_warnc(archive_errno(aw), "%s", archive_error_string(aw)); @@ -1010,7 +1048,8 @@ mode_list(struct cpio *cpio) archive_read_support_filter_all(a); archive_read_support_format_all(a); - if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) + if (archive_read_open_filename(a, cpio->filename, + cpio->bytes_per_block)) lafe_errc(1, archive_errno(a), "%s", archive_error_string(a)); for (;;) { @@ -1032,7 +1071,7 @@ mode_list(struct cpio *cpio) if (r != ARCHIVE_OK) lafe_errc(1, 0, "%s", archive_error_string(a)); if (!cpio->quiet) { - int64_t blocks = (archive_position_uncompressed(a) + 511) + int64_t blocks = (archive_filter_bytes(a, 0) + 511) / 512; fprintf(stderr, "%lu %s\n", (unsigned long)blocks, blocks == 1 ? "block" : "blocks"); @@ -1167,7 +1206,7 @@ mode_pass(struct cpio *cpio, const char *destdir) if (!cpio->quiet) { int64_t blocks = - (archive_position_uncompressed(cpio->archive) + 511) + (archive_filter_bytes(cpio->archive, 0) + 511) / 512; fprintf(stderr, "%lu %s\n", (unsigned long)blocks, blocks == 1 ? "block" : "blocks"); |