aboutsummaryrefslogtreecommitdiff
path: root/path.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-04-24 11:37:21 -0700
committerJunio C Hamano <gitster@pobox.com>2025-04-24 11:37:21 -0700
commitd61ff9c237b05f9cff0831d4bde546ed4a9c3c42 (patch)
tree4a787bfa36ba05fbcaefec1334b520a9f175935b /path.h
parent4bbb303af69990ccd05fe3a2eb58a1ce036f8220 (diff)
parent68cd492a3e662c75dec364986c81e94716d4ac56 (diff)
downloadgit-d61ff9c237b05f9cff0831d4bde546ed4a9c3c42.tar.xz
Merge branch 'ps/object-file-cleanup' into ps/object-store-cleanup
* ps/object-file-cleanup: object-store: merge "object-store-ll.h" and "object-store.h" object-store: remove global array of cached objects object: split out functions relating to object store subsystem object-file: drop `index_blob_stream()` object-file: split up concerns of `HASH_*` flags object-file: split out functions relating to object store subsystem object-file: move `xmmap()` into "wrapper.c" object-file: move `git_open_cloexec()` to "compat/open.c" object-file: move `safe_create_leading_directories()` into "path.c" object-file: move `mkdir_in_gitdir()` into "path.c"
Diffstat (limited to 'path.h')
-rw-r--r--path.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/path.h b/path.h
index 65fe968a13..fd1a194b06 100644
--- a/path.h
+++ b/path.h
@@ -221,6 +221,51 @@ char *xdg_cache_home(const char *filename);
*/
void safe_create_dir(struct repository *repo, const char *dir, int share);
+/*
+ * Similar to `safe_create_dir()`, but with two differences:
+ *
+ * - It knows to resolve gitlink files for symlinked worktrees.
+ *
+ * - It always adjusts shared permissions.
+ *
+ * Returns a negative erorr code on error, 0 on success.
+ */
+int safe_create_dir_in_gitdir(struct repository *repo, const char *path);
+
+/*
+ * Create the directory containing the named path, using care to be
+ * somewhat safe against races. Return one of the scld_error values to
+ * indicate success/failure. On error, set errno to describe the
+ * problem.
+ *
+ * SCLD_VANISHED indicates that one of the ancestor directories of the
+ * path existed at one point during the function call and then
+ * suddenly vanished, probably because another process pruned the
+ * directory while we were working. To be robust against this kind of
+ * race, callers might want to try invoking the function again when it
+ * returns SCLD_VANISHED.
+ *
+ * safe_create_leading_directories() temporarily changes path while it
+ * is working but restores it before returning.
+ * safe_create_leading_directories_const() doesn't modify path, even
+ * temporarily. Both these variants adjust the permissions of the
+ * created directories to honor core.sharedRepository, so they are best
+ * suited for files inside the git dir. For working tree files, use
+ * safe_create_leading_directories_no_share() instead, as it ignores
+ * the core.sharedRepository setting.
+ */
+enum scld_error {
+ SCLD_OK = 0,
+ SCLD_FAILED = -1,
+ SCLD_PERMS = -2,
+ SCLD_EXISTS = -3,
+ SCLD_VANISHED = -4
+};
+enum scld_error safe_create_leading_directories(struct repository *repo, char *path);
+enum scld_error safe_create_leading_directories_const(struct repository *repo,
+ const char *path);
+enum scld_error safe_create_leading_directories_no_share(char *path);
+
# ifdef USE_THE_REPOSITORY_VARIABLE
# include "strbuf.h"
# include "repository.h"