X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fmanifest.c;h=612a8a6d53ecfb1fe277483640b4fc080fcded06;hp=f7f86f74955548bd2c1f5568f851023b5e0e04c3;hb=09d5cd70d7e8105a003ed9583eadb077de014f3b;hpb=dc8042b42500f79f613b1197df6cdf739615a89f diff --git a/tools/manifest.c b/tools/manifest.c index f7f86f74..612a8a6d 100644 --- a/tools/manifest.c +++ b/tools/manifest.c @@ -3,6 +3,7 @@ #include "tools.h" #include #include +#include #include #include #include @@ -193,23 +194,22 @@ static void sort_files(struct list_head *list) struct manifest *get_manifest(const void *ctx, const char *dir) { struct manifest *m; - char *olddir, *canon_dir; + char *canon_dir; unsigned int len; struct list_head *list; + struct path_pushd *old; if (!manifests) { manifests = tal(NULL, struct htable_manifest); htable_manifest_init(manifests); } - olddir = tal_getcwd(NULL); - if (!olddir) - err(1, "Getting current directory"); - - if (chdir(dir) != 0) + /* FIXME: Use path_canon, don't chdir! */ + old = path_pushd(ctx, dir); + if (!old) err(1, "Failed to chdir to %s", dir); - canon_dir = tal_getcwd(olddir); + canon_dir = path_cwd(old); if (!canon_dir) err(1, "Getting current directory"); @@ -257,9 +257,8 @@ struct manifest *get_manifest(const void *ctx, const char *dir) htable_manifest_add(manifests, tal_link(manifests, m)); done: - if (chdir(olddir) != 0) - err(1, "Returning to original directory '%s'", olddir); - tal_free(olddir); + if (!path_popd(old)) + err(1, "Returning to original directory"); return m; }