pm

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

commit e592a819ac5982f7999174cbea4a4b9c76a24e99
parent 77b61b8c42ad62ed77124cf43cb68632ad9d5005
Author: z3bra <willyatmailoodotorg>
Date:   Fri Jun 17 01:10:22 +0200

Explode delete() in two functions

Diffstat:
pm.c | 43++++++++++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 11 deletions(-)
diff --git a/pm.c b/pm.c @@ -56,6 +56,7 @@ struct pack *pack_load_directory(const char *datadir, char *path); struct pack *pack_load(const char *datadir, char *path); void pack_free(struct pack *p); int pack_install(const char *rootfs, const char *datadir, struct pack *p); +int pack_delete(const char *rootfs, struct pack *p); int inspect_collision(const char *rootfs, struct pack *p); @@ -73,7 +74,7 @@ int delete_content(char *map, size_t size); /* action wrappers around CLI arguments */ int install(const char *rootfs, const char *datadir, char *path); int update(const char *rootfs, const char *datadir, char *path); -int delete(const char *rootfs, const char *datadir, const char *name); +int delete(const char *rootfs, const char *datadir, char *name); int verbose = 0; int overwrite = 0; @@ -535,16 +536,16 @@ delete_content(char *map, size_t size) * and call delete_content() */ int -delete(const char *rootfs, const char *datadir, const char *packname) +pack_delete(const char *rootfs, struct pack *p) { int fd; char *addr = NULL; char tmp[PATH_MAX]; struct stat st; - snprintf(tmp, PATH_MAX, "%s/%s/files", datadir, packname); + snprintf(tmp, PATH_MAX, "%s/files", p->path); if (stat(tmp, &st) < 0 && errno == ENOENT) { - fprintf(stderr, "%s: not installed\n", packname); + fprintf(stderr, "%s: not installed\n", p->name); return -1; } if ((fd = open(tmp, O_RDONLY)) < 0) { @@ -567,29 +568,28 @@ delete(const char *rootfs, const char *datadir, const char *packname) /* ignore errors so everything gets deleted */ if (delete_content(addr, st.st_size) < 0) { - fprintf(stderr, "%s: cannot remove pack\n", packname); + fprintf(stderr, "%s: cannot remove pack\n", p->name); close(fd); return ERR_DELETE; } close(fd); if (verbose == 1) - printf("%s: removing metadata\n", packname); + printf("%s: removing metadata\n", p->name); if (unlink(tmp) < 0) { perror(tmp); - fprintf(stderr, "%s: cannot remove file list\n", packname); + fprintf(stderr, "%s: cannot remove file list\n", p->name); return ERR_DELETE; } - snprintf(tmp, PATH_MAX, "%s/%s/version", datadir, packname); + snprintf(tmp, PATH_MAX, "%s/version", p->path); if (unlink(tmp) < 0) { perror(tmp); - fprintf(stderr, "%s: cannot clean version\n", packname); + fprintf(stderr, "%s: cannot clean version\n", p->name); return ERR_DELETE; } - snprintf(tmp, PATH_MAX, "%s/%s", datadir, packname); - return rmdir(tmp); + return rmdir(p->path); } @@ -635,6 +635,25 @@ update(const char *rootfs, const char *datadir, char *path) } +int +delete(const char *rootfs, const char *datadir, char *name) +{ + int r = 0; + struct pack *p = NULL; + char tmp[PATH_MAX] = ""; + + + snprintf(tmp, PATH_MAX, "%s/%s", datadir, name); + if ((p = pack_load(datadir, tmp)) == NULL) + return ERR_PACK_LOAD; + + r += pack_delete(rootfs, p); + pack_free(p); + + return r; +} + + /* * Load a pack from a tarball and return a pack structure */ @@ -686,6 +705,7 @@ pack_load_tarball(char *path) return pack; } + /* * Load a pack from a metadata directory and return a pack structure */ @@ -710,6 +730,7 @@ pack_load_directory(const char *datadir, char *path) return pack; } + /* * Guess how a pack should be loaded depending on the path given */