pm

barely a pack manager
git clone git://z3bra.org/pm
Log | Files | Refs | README | LICENSE

commit 505bcbe3ef7f29ac3f26f7d0b0f678a7efe53d55
parent 93c90c6b9d04d01fc6d7b5eefcb0ca488512beb7
Author: z3bra <willyatmailoodotorg>
Date:   Thu Jan  7 14:20:13 2016

Have unpack() rely on archive_read_extract()

Diffstat:
 pm.c | 27 ++++++---------------------
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/pm.c b/pm.c @@ -300,11 +300,7 @@ int unpack(char *root, char *in) { struct archive *a; - struct archive *w; /* write */ struct archive_entry *e; - const void *buf; - size_t len; - off_t off; int r; int mask = ARCHIVE_EXTRACT_PERM |ARCHIVE_EXTRACT_NO_OVERWRITE @@ -314,10 +310,6 @@ unpack(char *root, char *in) archive_read_support_filter_bzip2(a); archive_read_support_format_tar(a); - w = archive_write_disk_new(); - archive_write_disk_set_options(w, mask); - archive_write_disk_set_standard_lookup(w); - r = archive_read_open_filename(a, in, 0); if (r != ARCHIVE_OK) return r; @@ -329,28 +321,18 @@ unpack(char *root, char *in) } while (archive_read_next_header(a, &e) != ARCHIVE_EOF) { - - r = archive_write_header(w, e); if (r < ARCHIVE_OK) { - fprintf(stderr, "%s\n", archive_error_string(w)); + fprintf(stderr, "%s\n", archive_error_string(a)); return r; } if (archive_entry_size(e) > 0) - do { - r = archive_read_data_block(a, &buf, &len, &off); - if (r != ARCHIVE_OK) - return r; - /* returns the number of bytes written */ - r = archive_write_data_block(w, buf, len, off); - } while (r > 0); + r = archive_read_extract(a, e, mask); if (r < 0) return r; } archive_read_close(a); archive_read_free(a); - archive_write_close(w); - archive_write_free(w); return 0; } @@ -542,7 +524,10 @@ main (int argc, char **argv) while (*argv) { if ((p = pack_load(*(argv++)))) { metadata(PACKAGE_DATA, p); - unpack(PACKAGE_ROOT, p->path); + if (unpack(PACKAGE_ROOT, p->path) > 0) { + fprintf(stderr, "error unpacking %s\n", p->name); + delete(PACKAGE_DATA, PACKAGE_ROOT, p->name); + } pack_unload(p); } }