diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-12-03 16:13:06 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-12-03 16:13:06 -0800 |
commit | 39f04dbaacbb21864547c8cf087697469666d21e (patch) | |
tree | 260c02b84f44d35e91284e4771ff238c26805830 /environment.c | |
parent | 9bec60d3a52fa10b276214f8d255d6ff05a04b77 (diff) | |
parent | e0500293852910c2f44fce61e7eb856adbc20d8a (diff) | |
download | git-39f04dbaacbb21864547c8cf087697469666d21e.tar.gz |
Merge branch 'jn/thinner-wrapper'
* jn/thinner-wrapper:
Remove pack file handling dependency from wrapper.o
pack-objects: mark file-local variable static
wrapper: give zlib wrappers their own translation unit
strbuf: move strbuf_branchname to sha1_name.c
path helpers: move git_mkstemp* to wrapper.c
wrapper: move odb_* to environment.c
wrapper: move xmmap() to sha1_file.c
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 76e4dee273..913b0580af 100644 --- a/environment.c +++ b/environment.c @@ -172,6 +172,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) |