summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ff9206e)
raw | patch | inline | side by side (parent: ff9206e)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 6 Jul 2005 08:11:52 +0000 (01:11 -0700) | ||
committer | Linus Torvalds <torvalds@g5.osdl.org> | |
Wed, 6 Jul 2005 17:39:58 +0000 (10:39 -0700) |
The function write_one_ref() is passed the list of refs received
from the other end, which was obtained by directory traversal
under $GIT_DIR/refs; this can contain paths other than what
git-init-db prepares and would fail to clone when there is
such.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
from the other end, which was obtained by directory traversal
under $GIT_DIR/refs; this can contain paths other than what
git-init-db prepares and would fail to clone when there is
such.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
cache.h | patch | blob | history | |
clone-pack.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
index cc7b6db4b34b765a7d24827559c22c31bdb6309b..18584c99cf5b04345c9cc1f5015153a23197dccb 100644 (file)
--- a/cache.h
+++ b/cache.h
extern char *git_path(const char *fmt, ...);
extern char *sha1_file_name(const unsigned char *sha1);
+int safe_create_leading_directories(char *path);
+
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
extern void * map_sha1_file(const unsigned char *sha1, unsigned long *size);
extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size);
diff --git a/clone-pack.c b/clone-pack.c
index 0337ceccc4153b19dcffdee8c03c373b972fc6a8..b9b8437dd51d0059f056d42300f773ac8324448f 100644 (file)
--- a/clone-pack.c
+++ b/clone-pack.c
static void write_one_ref(struct ref *ref)
{
char *path = git_path(ref->name);
- int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666);
+ int fd;
char *hex;
+ if (safe_create_leading_directories(path))
+ die("unable to create leading directory for %s", ref->name);
+ fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd < 0)
die("unable to create ref %s", ref->name);
hex = sha1_to_hex(ref->sha1);
diff --git a/sha1_file.c b/sha1_file.c
index 1747276647c7551fd3fe7b1a20612341c0d00d6f..fd6096f4170f2db58320dc7d7e16f25b6c7fd0c9 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
return ret;
}
+int safe_create_leading_directories(char *path)
+{
+ char *pos = path;
+
+ while (pos) {
+ pos = strchr(pos, '/');
+ if (!pos)
+ break;
+ *pos = 0;
+ if (mkdir(path, 0777) < 0)
+ if (errno != EEXIST) {
+ *pos = '/';
+ return -1;
+ }
+ *pos++ = '/';
+ }
+ return 0;
+}
+
int get_sha1(const char *str, unsigned char *sha1)
{
static const char *prefix[] = {