environment: move object database functions into object layer
The `odb_mkstemp()` and `odb_pack_keep()` functions are quite clearly tied to the object store, but regardless of that they are located in "environment.c". Move them over, which also helps to get rid of dependencies on `the_repository` in the environment subsystem. 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
b92266b79c
commit
26b4df907b
@ -419,6 +419,39 @@ enum scld_error safe_create_leading_directories_const(const char *path)
|
||||
return result;
|
||||
}
|
||||
|
||||
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
|
||||
{
|
||||
int fd;
|
||||
/*
|
||||
* we let the umask do its job, don't try to be more
|
||||
* restrictive except to remove write permission.
|
||||
*/
|
||||
int mode = 0444;
|
||||
git_path_buf(temp_filename, "objects/%s", pattern);
|
||||
fd = git_mkstemp_mode(temp_filename->buf, mode);
|
||||
if (0 <= fd)
|
||||
return fd;
|
||||
|
||||
/* slow path */
|
||||
/* some mkstemp implementations erase temp_filename on failure */
|
||||
git_path_buf(temp_filename, "objects/%s", pattern);
|
||||
safe_create_leading_directories(temp_filename->buf);
|
||||
return xmkstemp_mode(temp_filename->buf, mode);
|
||||
}
|
||||
|
||||
int odb_pack_keep(const char *name)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||
if (0 <= fd)
|
||||
return fd;
|
||||
|
||||
/* slow path */
|
||||
safe_create_leading_directories_const(name);
|
||||
return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||
}
|
||||
|
||||
static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
|
||||
{
|
||||
int i;
|
||||
|
Reference in New Issue
Block a user