pm

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

commit 124b13d5f0ddef0e683c239655108a1fadb38c66
parent f31eb71cbd3446251a1e6ced34dffe41ec6f8525
Author: z3bra <willyatmailoodotorg>
Date:   Sun Jan 10 12:48:56 2016

Have perror() output the target

Diffstat:
 pm.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/pm.c b/pm.c @@ -52,6 +52,7 @@ int list_archive(int fd, char *filename); int list_local(int fd, char *packname); int list_content(int fd, char *packname); int metadata(char *datadir, struct pack *pack); +int write_on_disk(struct archive *a, struct archive *w); int unpack(char *root, char *in); int delete_content(FILE *metafile); int delete(const char *datadir, const char *rootfs, const char *name); @@ -78,7 +79,7 @@ is_empty(char *dir) struct dirent *p; if (!(d = opendir(dir))) { - perror("opendir"); + perror(dir); return -1; } @@ -194,7 +195,7 @@ list_content(int fd, char *name) snprintf(tmp, PATH_MAX, "%s/%s/files", PACKAGE_DATA, name); if ((meta = open(tmp, O_RDONLY)) < 0) { - perror("open"); + perror(tmp); return -1; } @@ -221,7 +222,7 @@ list_local(int fd, char *datadir) size_t len; if (!(d = opendir(datadir))) { - perror("opendir"); + perror(datadir); return -1; } @@ -231,7 +232,7 @@ list_local(int fd, char *datadir) datadir, p->d_name); if ((meta = open(tmp, O_RDONLY)) < 0) { - perror("open"); + perror(tmp); closedir(d); return 1; } @@ -273,7 +274,7 @@ metadata(char *datadir, struct pack *pack) snprintf(tmp, PATH_MAX, "%s/%s/files", datadir, pack->name); fd = open(tmp, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd < 0) { - perror("open"); + perror(tmp); return -1; } list_archive(fd, pack->path); @@ -282,7 +283,7 @@ metadata(char *datadir, struct pack *pack) snprintf(tmp, PATH_MAX, "%s/%s/version", datadir, pack->name); fd = open(tmp, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd < 0) { - perror("open"); + perror(tmp); return -1; } @@ -290,7 +291,7 @@ metadata(char *datadir, struct pack *pack) r += write(fd, "\n", 1); if (r < 1) { - perror("write"); + perror(tmp); return -1; } close(fd); @@ -342,12 +343,14 @@ unpack(char *root, char *in) archive_write_disk_set_options(disk, mask); r = archive_read_open_filename(a, in, 0); - if (r != ARCHIVE_OK) + if (r != ARCHIVE_OK) { + fprintf(stderr, "%s\n", archive_error_string(a)); return r; + } /* extract the pack at the specified root */ if (chdir(root) < 0) { - perror("chdir"); + perror(root); return -1; } @@ -358,12 +361,14 @@ unpack(char *root, char *in) } r = archive_write_header(disk, e); - if (r != ARCHIVE_OK) - return r; - write_on_disk(a, disk); - r = archive_write_finish_entry(disk); - if (r != 0) + if (r != ARCHIVE_OK) { + fprintf(stderr, "%s\n", archive_error_string(a)); return r; + } + if (write_on_disk(a, disk) != ARCHIVE_OK) { + fprintf(stderr, "%s\n", archive_error_string(disk)); + } + archive_write_finish_entry(disk); } archive_read_close(a); archive_read_free(a); @@ -410,7 +415,7 @@ delete_content(FILE *f) return rmdir(file); if (unlink(file) < 0) { - perror("unlink"); + perror(file); return -1; } @@ -433,12 +438,12 @@ delete(const char *datadir, const char *rootfs, const char *name) snprintf(meta, PATH_MAX, "%s/%s/files", datadir, name); if ((f = fopen(meta, "r")) == NULL) { - perror("fopen"); + perror(meta); return -1; } if (chdir(rootfs) < 0) { - perror("chdir"); + perror(rootfs); return -1; } @@ -466,7 +471,7 @@ pack_load_file(char *path) char *p; if ((fd = open(path, O_RDONLY)) < 0) { - perror("open"); + perror(path); free(pack); return NULL; }