pm

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

commit 07cdaa8ebcaebae5fb50e9b28b6977445418bd86
parent 6e855748b4844361a463e1e0d3a48f04c45eefdf
Author: z3bra <willyatmailoodotorg>
Date:   Sun Jun 19 01:39:13 +0200

Make update() perform an install with overwrite flag set

Diffstat:
pm.c | 22++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/pm.c b/pm.c @@ -61,7 +61,7 @@ int mkdir_parents(char *dir, mode_t mode); char *base_name(char *path); struct pack *pack_load_tarball(char *path); -struct pack *pack_load_directory(const char *datadir, char *path); +struct pack *pack_load_metadata(const char *datadir, char *name); struct pack *pack_load(const char *datadir, char *path); void pack_free(struct pack *p); int pack_extract(const char *rootfs, const char *datadir, struct pack *p); @@ -212,9 +212,10 @@ pack_load_tarball(char *path) * Load a pack from a metadata directory and return a pack structure */ struct pack * -pack_load_directory(const char *datadir, char *path) +pack_load_metadata(const char *datadir, char *name) { struct pack *pack = NULL; + char tmp[PATH_MAX] = ""; if (!(pack = malloc(sizeof(struct pack)))) { perror("malloc"); @@ -225,8 +226,9 @@ pack_load_directory(const char *datadir, char *path) pack->name = NULL; pack->version = malloc(LINE_MAX); - pack->path = strdup(path); - pack->name = strdup(base_name(path)); + snprintf(tmp, PATH_MAX, "%s/%s", datadir, name); + pack->path = strdup(tmp); + pack->name = strdup(name); inspect_version(datadir, pack->name, pack->version); return pack; @@ -244,10 +246,10 @@ pack_load(const char *datadir, char *path) if (stat(path, &st) < 0) { perror(path); - } else if (S_ISDIR(st.st_mode)) { - p = pack_load_directory(datadir, path); } else if (S_ISREG(st.st_mode)) { p = pack_load_tarball(path); + } else if (S_ISDIR(st.st_mode)) { + p = pack_load_metadata(datadir, path); } return p; @@ -743,7 +745,7 @@ install(const char *rootfs, const char *datadir, char *path) int update(const char *rootfs, const char *datadir, char *path) { - int r = 0; + int r = 0, tmp = overwrite; struct pack *p = NULL; if ((p = pack_load(datadir, path)) == NULL) @@ -752,7 +754,9 @@ update(const char *rootfs, const char *datadir, char *path) if (pack_delete(rootfs, datadir, p) != 0) return ERR_DELETE; + overwrite = 1; r += pack_install(rootfs, datadir, p); + overwrite = tmp; if (r == 0) log(LOG_INFO, "updated %s to %s\n", p->name, p->version); @@ -773,11 +777,9 @@ delete(const char *rootfs, const char *datadir, char *name) struct pack *p = NULL; char tmp[PATH_MAX] = ""; - snprintf(tmp, PATH_MAX, "%s/%s", datadir, name); - if ((p = pack_load(datadir, tmp)) == NULL) + if ((p = pack_load(datadir, name)) == NULL) return ERR_PACK_LOAD; - r += pack_delete(rootfs, datadir, p); if (r == 0)