X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=wrapper.c;h=d8efb1365a01104db568633fa8f6aef0c67b4cd1;hb=7f733de04e69c8ba40158d1da46c4aa121f714b6;hp=c85ca52ec63a679a2da7bd8980ad4e2df4e38794;hpb=9a01387b9714452ebcae431705a288e1a7e099c3;p=git.git diff --git a/wrapper.c b/wrapper.c index c85ca52ec..d8efb1365 100644 --- a/wrapper.c +++ b/wrapper.c @@ -256,3 +256,36 @@ int git_inflate(z_streamp strm, int flush) error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message"); return ret; } + +int odb_mkstemp(char *template, size_t limit, const char *pattern) +{ + int fd; + + snprintf(template, limit, "%s/%s", + get_object_directory(), pattern); + fd = mkstemp(template); + 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(template); +} + +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); +}