1057
enum scld_error safe_create_leading_directories(char *path);
1058
enum scld_error safe_create_leading_directories_const(const char *path);
1059
1060
+/*
1061
+ * Callback function for raceproof_create_file(). This function is
1062
+ * expected to do something that makes dirname(path) permanent despite
1063
+ * the fact that other processes might be cleaning up empty
1064
+ * directories at the same time. Usually it will create a file named
1065
+ * path, but alternatively it could create another file in that
1066
+ * directory, or even chdir() into that directory. The function should
1067
+ * return 0 if the action was completed successfully. On error, it
1068
+ * should return a nonzero result and set errno.
1069
+ * raceproof_create_file() treats two errno values specially:
1070
+ *
1071
+ * - ENOENT -- dirname(path) does not exist. In this case,
1072
+ * raceproof_create_file() tries creating dirname(path)
1073
+ * (and any parent directories, if necessary) and calls
1074
+ * the function again.
1075
+ *
1076
+ * - EISDIR -- the file already exists and is a directory. In this
1077
+ * case, raceproof_create_file() removes the directory if
1078
+ * it is empty (and recursively any empty directories that
1079
+ * it contains) and calls the function again.
1080
+ *
1081
+ * Any other errno causes raceproof_create_file() to fail with the
1082
+ * callback's return value and errno.
1083
+ *
1084
+ * Obviously, this function should be OK with being called again if it
1085
+ * fails with ENOENT or EISDIR. In other scenarios it will not be
1086
+ * called again.
1087
+ */
1088
+typedef int create_file_fn(const char *path, void *cb);
1089
+
1090
+/*
1091
+ * Create a file in dirname(path) by calling fn, creating leading
1092
+ * directories if necessary. Retry a few times in case we are racing
1093
+ * with another process that is trying to clean up the directory that
1094
+ * contains path. See the documentation for create_file_fn for more
1095
+ * details.
1096
+ *
1097
+ * Return the value and set the errno that resulted from the most
1098
+ * recent call of fn. fn is always called at least once, and will be
1099
+ * called more than once if it returns ENOENT or EISDIR.
1100
+ */
1101
+int raceproof_create_file(const char *path, create_file_fn fn, void *cb);
1102
+
1103
int mkdir_in_gitdir(const char *path);
1104
extern char *expand_user_path(const char *path);
1105
const char *enter_repo(const char *path, int strict);