summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c81
1 files changed, 2 insertions, 79 deletions
diff --git a/object-file.c b/object-file.c
index 00451876bd..6228e1c40f 100644
--- a/object-file.c
+++ b/object-file.c
@@ -90,83 +90,6 @@ static int get_conv_flags(unsigned flags)
return 0;
}
-static enum scld_error safe_create_leading_directories_1(char *path, int share)
-{
- char *next_component = path + offset_1st_component(path);
- enum scld_error ret = SCLD_OK;
-
- while (ret == SCLD_OK && next_component) {
- struct stat st;
- char *slash = next_component, slash_character;
-
- while (*slash && !is_dir_sep(*slash))
- slash++;
-
- if (!*slash)
- break;
-
- next_component = slash + 1;
- while (is_dir_sep(*next_component))
- next_component++;
- if (!*next_component)
- break;
-
- slash_character = *slash;
- *slash = '\0';
- if (!stat(path, &st)) {
- /* path exists */
- if (!S_ISDIR(st.st_mode)) {
- errno = ENOTDIR;
- ret = SCLD_EXISTS;
- }
- } else if (mkdir(path, 0777)) {
- if (errno == EEXIST &&
- !stat(path, &st) && S_ISDIR(st.st_mode))
- ; /* somebody created it since we checked */
- else if (errno == ENOENT)
- /*
- * Either mkdir() failed because
- * somebody just pruned the containing
- * directory, or stat() failed because
- * the file that was in our way was
- * just removed. Either way, inform
- * the caller that it might be worth
- * trying again:
- */
- ret = SCLD_VANISHED;
- else
- ret = SCLD_FAILED;
- } else if (share && adjust_shared_perm(the_repository, path)) {
- ret = SCLD_PERMS;
- }
- *slash = slash_character;
- }
- return ret;
-}
-
-enum scld_error safe_create_leading_directories(char *path)
-{
- return safe_create_leading_directories_1(path, 1);
-}
-
-enum scld_error safe_create_leading_directories_no_share(char *path)
-{
- return safe_create_leading_directories_1(path, 0);
-}
-
-enum scld_error safe_create_leading_directories_const(const char *path)
-{
- int save_errno;
- /* path points to cache entries, so xstrdup before messing with it */
- char *buf = xstrdup(path);
- enum scld_error result = safe_create_leading_directories(buf);
-
- save_errno = errno;
- free(buf);
- errno = save_errno;
- return result;
-}
-
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
{
int fd;
@@ -183,7 +106,7 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
/* slow path */
/* some mkstemp implementations erase temp_filename on failure */
repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
- safe_create_leading_directories(temp_filename->buf);
+ safe_create_leading_directories(the_repository, temp_filename->buf);
return xmkstemp_mode(temp_filename->buf, mode);
}
@@ -196,7 +119,7 @@ int odb_pack_keep(const char *name)
return fd;
/* slow path */
- safe_create_leading_directories_const(name);
+ safe_create_leading_directories_const(the_repository, name);
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
}