Merge branch 'jc/maint-1.6.0-pack-directory'
[gitweb.git] / wrapper.c
index c85ca52ec63a679a2da7bd8980ad4e2df4e38794..b07cdf299af66d4c503d5a788858b9cc56683143 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -256,3 +256,35 @@ 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 */
+       safe_create_leading_directories(template);
+       snprintf(template, limit, "%s/%s",
+                get_object_directory(), pattern);
+       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);
+}