object-store: move and rename odb_pack_keep()
The function `odb_pack_keep()` creates a file at the passed-in path. If this fails, then the function re-tries by first creating any potentially missing leading directories and then trying to create the file once again. As such, this function doesn't host any kind of logic that is specific to the object store, but is rather a generic helper function. Rename the function to `safe_create_file_with_leading_directories()` and move it into "path.c". While at it, refactor it so that it loses its dependency on `the_repository`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
56ef85e82f
commit
0b8ed25b66
14
path.c
14
path.c
@@ -1011,6 +1011,20 @@ enum scld_error safe_create_leading_directories_const(struct repository *repo,
|
||||
return result;
|
||||
}
|
||||
|
||||
int safe_create_file_with_leading_directories(struct repository *repo,
|
||||
const char *path)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(path, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||
if (0 <= fd)
|
||||
return fd;
|
||||
|
||||
/* slow path */
|
||||
safe_create_leading_directories_const(repo, path);
|
||||
return open(path, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||
}
|
||||
|
||||
static int have_same_root(const char *path1, const char *path2)
|
||||
{
|
||||
int is_abs1, is_abs2;
|
||||
|
||||
Reference in New Issue
Block a user