tHave perror() output the target - pm - barely a pack manager
(HTM) git clone git://z3bra.org/pm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 124b13d5f0ddef0e683c239655108a1fadb38c66
(DIR) parent f31eb71cbd3446251a1e6ced34dffe41ec6f8525
(HTM) Author: z3bra <willyatmailoodotorg>
Date: Sun, 10 Jan 2016 12:48:56 +0100
Have perror() output the target
Diffstat:
M pm.c | 41 +++++++++++++++++--------------
1 file changed, 23 insertions(+), 18 deletions(-)
---
(DIR) diff --git a/pm.c b/pm.c
t@@ -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);
t@@ -78,7 +79,7 @@ is_empty(char *dir)
struct dirent *p;
if (!(d = opendir(dir))) {
- perror("opendir");
+ perror(dir);
return -1;
}
t@@ -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;
}
t@@ -221,7 +222,7 @@ list_local(int fd, char *datadir)
size_t len;
if (!(d = opendir(datadir))) {
- perror("opendir");
+ perror(datadir);
return -1;
}
t@@ -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;
}
t@@ -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);
t@@ -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;
}
t@@ -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);
t@@ -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;
}
t@@ -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);
t@@ -410,7 +415,7 @@ delete_content(FILE *f)
return rmdir(file);
if (unlink(file) < 0) {
- perror("unlink");
+ perror(file);
return -1;
}
t@@ -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;
}
t@@ -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;
}