diff options
author | Jonathan Nieder <jrnieder@gmail.com> | 2010-11-06 06:45:38 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-10 11:03:38 -0800 |
commit | 463db9b104b5db7d574ce4c5ede8caaa6d02ff4c (patch) | |
tree | 1be5e1190a0bd603e612286e63c36cd1d105841c /environment.c | |
parent | 58ecbd5edeb2357c313db75bc49d45981a2061b7 (diff) | |
download | git-463db9b104b5db7d574ce4c5ede8caaa6d02ff4c.tar.gz |
wrapper: move odb_* to environment.c
The odb_mkstemp and odb_pack_keep functions open files under the
$GIT_OBJECT_DIRECTORY directory. This requires access to the git
configuration which very simple programs do not need.
Move these functions to environment.o, closer to their dependencies.
This should make it easier for programs to link to wrapper.o without
linking to environment.o.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r-- | environment.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/environment.c b/environment.c index de5581fe51..95777f4c7f 100644 --- a/environment.c +++ b/environment.c @@ -171,6 +171,43 @@ char *get_object_directory(void) return git_object_dir; } +int odb_mkstemp(char *template, size_t limit, 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; + snprintf(template, limit, "%s/%s", + get_object_directory(), pattern); + fd = git_mkstemp_mode(template, mode); + if (0 <= fd) + return fd; + + /* slow path */ + /* some mkstemp implementations erase template on failure */ + snprintf(template, limit, "%s/%s", + get_object_directory(), pattern); + safe_create_leading_directories(template); + return xmkstemp_mode(template, mode); +} + +int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1) +{ + int fd; + + snprintf(name, namesz, "%s/pack/pack-%s.keep", + get_object_directory(), sha1_to_hex(sha1)); + fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); + if (0 <= fd) + return fd; + + /* slow path */ + safe_create_leading_directories(name); + return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); +} + char *get_index_file(void) { if (!git_index_file) |