[PATCH] clone-pack.c:write_one_ref() - Create leading directories.
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>maint
parent
ff9206e72c
commit
b2cb94254b
2
cache.h
2
cache.h
|
@ -161,6 +161,8 @@ extern void rollback_index_file(struct cache_file *);
|
||||||
extern char *git_path(const char *fmt, ...);
|
extern char *git_path(const char *fmt, ...);
|
||||||
extern char *sha1_file_name(const unsigned char *sha1);
|
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 */
|
/* 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 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);
|
extern int unpack_sha1_header(z_stream *stream, void *map, unsigned long mapsize, void *buffer, unsigned long size);
|
||||||
|
|
|
@ -68,9 +68,12 @@ static int is_master(struct ref *ref)
|
||||||
static void write_one_ref(struct ref *ref)
|
static void write_one_ref(struct ref *ref)
|
||||||
{
|
{
|
||||||
char *path = git_path(ref->name);
|
char *path = git_path(ref->name);
|
||||||
int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, 0666);
|
int fd;
|
||||||
char *hex;
|
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)
|
if (fd < 0)
|
||||||
die("unable to create ref %s", ref->name);
|
die("unable to create ref %s", ref->name);
|
||||||
hex = sha1_to_hex(ref->sha1);
|
hex = sha1_to_hex(ref->sha1);
|
||||||
|
|
19
sha1_file.c
19
sha1_file.c
|
@ -130,6 +130,25 @@ char *git_path(const char *fmt, ...)
|
||||||
return ret;
|
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)
|
int get_sha1(const char *str, unsigned char *sha1)
|
||||||
{
|
{
|
||||||
static const char *prefix[] = {
|
static const char *prefix[] = {
|
||||||
|
|
Loading…
Reference in New Issue