diff options
author | cperciva <cperciva@FreeBSD.org> | 2007-03-31 10:14:03 +0000 |
---|---|---|
committer | cperciva <cperciva@FreeBSD.org> | 2007-03-31 10:14:03 +0000 |
commit | 04b5ff28d3ffdeb6c23f06667d7f32ec7ee176e8 (patch) | |
tree | 558236967bd5f371f6baae91b4cff214fbc015bb /usr.bin/tar | |
parent | 307e4679c3315c4b15ea5b7bf814bc64bfc9bc88 (diff) | |
download | FreeBSD-src-04b5ff28d3ffdeb6c23f06667d7f32ec7ee176e8.zip FreeBSD-src-04b5ff28d3ffdeb6c23f06667d7f32ec7ee176e8.tar.gz |
Split the append_archive function (used for processing @<archive> directives)
into separate append_archive and append_archive_filename functions; the first
takes a "struct archive *" as input, while the second takes a filename, opens
the archive, and calls the first.
There should be no changes in behaviour as a result of this commit; it simply
reorganizes code to make more sense. At some point in the future it may be
possible to share code between append_archive and read_archive, but not yet.
Discussed with: kientzle
Diffstat (limited to 'usr.bin/tar')
-rw-r--r-- | usr.bin/tar/write.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/usr.bin/tar/write.c b/usr.bin/tar/write.c index 267eac4..4226ca2 100644 --- a/usr.bin/tar/write.c +++ b/usr.bin/tar/write.c @@ -129,7 +129,9 @@ struct name_cache { static void add_dir_list(struct bsdtar *bsdtar, const char *path, time_t mtime_sec, int mtime_nsec); static int append_archive(struct bsdtar *, struct archive *, - const char *fname); + struct archive *ina); +static int append_archive_filename(struct bsdtar *, + struct archive *, const char *fname); static void archive_names_from_file(struct bsdtar *bsdtar, struct archive *a); static int archive_names_from_file_helper(struct bsdtar *bsdtar, @@ -453,7 +455,8 @@ write_archive(struct archive *a, struct bsdtar *bsdtar) if (*arg != '/' && (arg[0] != '@' || arg[1] != '/')) do_chdir(bsdtar); /* Handle a deferred -C */ if (*arg == '@') { - if (append_archive(bsdtar, a, arg + 1) != 0) + if (append_archive_filename(bsdtar, a, + arg + 1) != 0) break; } else write_hierarchy(bsdtar, a, arg); @@ -513,12 +516,11 @@ archive_names_from_file_helper(struct bsdtar *bsdtar, const char *line) * operation will complete and return non-zero. */ static int -append_archive(struct bsdtar *bsdtar, struct archive *a, const char *filename) +append_archive_filename(struct bsdtar *bsdtar, struct archive *a, + const char *filename) { struct archive *ina; - struct archive_entry *in_entry; - int bytes_read, bytes_written; - char buff[8192]; + int rc; if (strcmp(filename, "-") == 0) filename = NULL; /* Library uses NULL for stdio. */ @@ -531,6 +533,26 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, const char *filename) bsdtar->return_value = 1; return (0); } + + rc = append_archive(bsdtar, a, ina); + + if (archive_errno(ina)) { + bsdtar_warnc(bsdtar, 0, "Error reading archive %s: %s", + filename, archive_error_string(ina)); + bsdtar->return_value = 1; + } + archive_read_finish(ina); + + return (rc); +} + +static int +append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina) +{ + struct archive_entry *in_entry; + int bytes_read, bytes_written; + char buff[8192]; + while (0 == archive_read_next_header(ina, &in_entry)) { if (!new_enough(bsdtar, archive_entry_pathname(in_entry), archive_entry_stat(in_entry))) @@ -564,14 +586,7 @@ append_archive(struct bsdtar *bsdtar, struct archive *a, const char *filename) } if (bsdtar->verbose) fprintf(stderr, "\n"); - } - if (archive_errno(ina)) { - bsdtar_warnc(bsdtar, 0, "Error reading archive %s: %s", - filename, archive_error_string(ina)); - bsdtar->return_value = 1; - } - archive_read_finish(ina); /* Note: If we got here, we saw no write errors, so return success. */ return (0); |