pm

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

commit e9711c9b1d1dc9fd7c3741309cd879cda2ebabc6
parent 11ca8f6728acf195601b904ac0c90cbfff2f2f8f
Author: z3bra <willyatmailoodotorg>
Date:   Wed Jun 22 10:20:56 +0200

Fix bug in inspect_installed()

Diffstat:
pm.c | 23+++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/pm.c b/pm.c @@ -368,12 +368,11 @@ pack_install(const char *rootfs, const char *datadir, struct pack *p) { int r; char tmp[PATH_MAX] = ""; - struct stat st; if (overwrite == 0) { snprintf(tmp, PATH_MAX, "%s/%s", datadir, p->name); log(LOG_VERBOSE, "checking installation status\n"); - if (stat(tmp, &st) == 0 && S_ISDIR(st.st_mode)) { + if (inspect_installed(datadir, p->name) == 0) { fprintf(stderr, "%s: Pack already installed\n", p->name); return -1; } @@ -384,12 +383,17 @@ pack_install(const char *rootfs, const char *datadir, struct pack *p) log(LOG_VERBOSE, "writing metadata\n"); if (write_metadata(datadir, p) < 0) { - perror(datadir); + delete_metadata(datadir, p->name); return -1; } r = pack_extract(rootfs, datadir, p); + if (r != 0) { + fprintf(stderr, "%s: Installation failed. Deleting pack\n", p->name); + pack_delete(rootfs, datadir, p); + } + return r; } @@ -456,7 +460,8 @@ inspect_installed(const char *datadir, const char *name) struct stat st; snprintf(tmp, PATH_MAX, "%s/%s", datadir, name); - return stat(tmp, &st) || S_ISDIR(st.st_mode); + log(LOG_VERBOSE, "checking existence of %s\n", tmp); + return stat(tmp, &st) || !S_ISDIR(st.st_mode); } @@ -799,19 +804,17 @@ update(const char *rootfs, const char *datadir, char *path) return ERR_DELETE; } - if (pack_delete(rootfs, datadir, p) != 0) + if (pack_delete(rootfs, datadir, p) != 0) { + pack_free(p); return ERR_DELETE; + } overwrite = 1; r += pack_install(rootfs, datadir, p); overwrite = tmp; - if (r == 0) { + if (r == 0) log(LOG_INFO, "updated %s to %s\n", p->name, p->version); - } else { - fprintf(stderr, "%s: Update failed. Cleaning filesystem\n", p->name); - pack_delete(rootfs, datadir, p); - } pack_free(p);