Repositories / jai.git
jai.git
Clone (read-only): git clone http://git.guha-anderson.com/git/jai.git
@@ -187,11 +187,12 @@ is_dir_empty(int dirfd) Fd ensure_dir(int dfd, const path &p, mode_t perm, FollowLinks follow, - bool okay_if_other_owner) + bool okay_if_other_owner, std::function<void(int)> createcb) { assert(!p.empty()); Fd fd; + bool created = false; int flag = follow == kFollow ? 0 : O_NOFOLLOW; if (p.is_absolute()) dfd = *(fd = xopenat(-1, "/", O_RDONLY)); @@ -204,7 +205,8 @@ ensure_dir(int dfd, const path &p, mode_t perm, FollowLinks follow, else if (errno != ENOENT) syserr(R"(ensure_dir("{}"): open("{}"))", p.string(), fdpath(dfd, *component)); - else if (mkdirat(dfd, component->c_str(), perm) && errno != EEXIST) + else if (created = !mkdirat(dfd, component->c_str(), perm), + !created && errno != EEXIST) syserr(R"(ensure_dir("{}"): mkdir("{}"))", p.string(), fdpath(dfd, *component)); else if (struct stat sb; fstatat(dfd, component->c_str(), &sb, 0))
@@ -10,6 +10,7 @@ #include <filesystem> #include <ranges> #include <set> +#include <functional> #include <string> #include <string_view> @@ -160,7 +161,8 @@ bool is_fd_at_path(int targetfd, int dfd, const path &file, bool is_dir_empty(int dirfd); Fd ensure_dir(int dfd, const path &p, mode_t perm, FollowLinks follow, - bool okay_if_other_owner = false); + bool okay_if_other_owner = false, + std::function<void(int)> createcb = [](int) {}); void make_whiteout(int dfd, const path &p);