pm

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

commit 6e855748b4844361a463e1e0d3a48f04c45eefdf
parent 9aee903d9fa062136b5e605cc0b43e7c03252d49
Author: z3bra <willyatmailoodotorg>
Date:   Sun Jun 19 01:18:18 +0200

Avoid chdir() and work with absolute path

Diffstat:
pm.c | 21+++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/pm.c b/pm.c @@ -76,7 +76,7 @@ int inspect_system(int fd, const char *datadir); int write_metadata(const char *datadir, struct pack *pack); int write_entry(struct archive *a, struct archive *w); int delete_node(char *path); -int delete_content(char *map, size_t size); +int delete_content(const char *rootfs, char *map, size_t size); /* action wrappers around CLI arguments */ int install(const char *rootfs, const char *datadir, char *path); @@ -392,7 +392,7 @@ pack_delete(const char *rootfs, const char *datadir, struct pack *p) { int fd; char *addr = NULL; - char tmp[PATH_MAX], cwd[PATH_MAX]; + char tmp[PATH_MAX]; struct stat st; snprintf(tmp, PATH_MAX, "%s/%s/files", datadir, p->name); @@ -411,16 +411,9 @@ pack_delete(const char *rootfs, const char *datadir, struct pack *p) close(fd); } - getcwd(cwd, PATH_MAX); - if (chdir(rootfs) < 0) { - perror(rootfs); - close(fd); - return ERR_DELETE; - } - log(LOG_VERBOSE, "deleting installed files\n"); /* ignore errors so everything gets deleted */ - if (delete_content(addr, st.st_size) < 0) { + if (delete_content(rootfs, addr, st.st_size) < 0) { fprintf(stderr, "%s: pack not removed\n", p->name); close(fd); return ERR_DELETE; @@ -447,8 +440,6 @@ pack_delete(const char *rootfs, const char *datadir, struct pack *p) log(LOG_DEBUG, "- %s\n", tmp); rmdir(tmp); - chdir(cwd); - return 0; } @@ -682,9 +673,10 @@ delete_node(char *path) * if the entry doesn't exist, it will be ignored */ int -delete_content(char *map, size_t size) +delete_content(const char *rootfs, char *map, size_t size) { char *path = NULL; + char tmp[PATH_MAX] = ""; size_t off; if (size < 1) @@ -710,7 +702,8 @@ delete_content(char *map, size_t size) path = (off < size-1 ? &map[off] + (off>0?1:0) : NULL); if (path != NULL && strnlen(path, PATH_MAX) > 0) { - if (delete_node(path) < 0) + snprintf(tmp, PATH_MAX, "%s%s", rootfs, path); + if (delete_node(tmp) < 0) return ERR_DELETE; } } while (off > 0);