Repositories / jai.git

jai.git

Clone (read-only): git clone http://git.guha-anderson.com/git/jai.git

Branch

fix ensure_dir

Author
David Mazieres <dm@uun.org>
Date
2026-03-16 20:42:40 -0700
Commit
a4261f3bb7adfa91b5678511c7dfe69962726813
fs.cc
index 7a86eb0..d7dab25 100644
--- a/fs.cc
+++ b/fs.cc
@@ -205,17 +205,17 @@ ensure_dir(int dfd, const path &p, mode_t perm, FollowLinks follow,
     }
     else if (errno != ENOENT)
       syserr(R"(ensure_dir("{}"): open("{}"))", p.string(),
-             component->string());
+             fdpath(dfd, *component));
+    else if (mkdirat(dfd, component->c_str(), perm) && errno != EEXIST)
+      syserr(R"(ensure_dir("{}"): mkdir("{}"))", p.string(),
+             fdpath(dfd, *component));
     else if (struct stat sb; fstatat(dfd, component->c_str(), &sb, 0))
       syserr(R"(ensure_dir("{}"): stat("{}"))", p.string(),
-             component->string());
+             fdpath(dfd, *component));
     else if (!S_ISDIR(sb.st_mode)) {
       syserr(R"(ensure_dir("{}"): "{}" is not a directory)", p.string(),
-             component->string());
+             fdpath(dfd, *component));
     }
-    else if (mkdirat(dfd, component->c_str(), perm) && errno != EEXIST)
-      syserr(R"(ensure_dir("{}"): mkdir("{}"))", p.string(),
-             component->string());
     // Don't advance iterator; want to open directory we just created
   }