Merge branch 'jc/maint-1.6.0-pack-directory'
* jc/maint-1.6.0-pack-directory: Make sure objects/pack exists before creating a new pack
This commit is contained in:
commit
bb0cebd7d0
@ -488,9 +488,8 @@ static void write_pack_file(void)
|
|||||||
} else {
|
} else {
|
||||||
char tmpname[PATH_MAX];
|
char tmpname[PATH_MAX];
|
||||||
int fd;
|
int fd;
|
||||||
snprintf(tmpname, sizeof(tmpname),
|
fd = odb_mkstemp(tmpname, sizeof(tmpname),
|
||||||
"%s/pack/tmp_pack_XXXXXX", get_object_directory());
|
"pack/tmp_pack_XXXXXX");
|
||||||
fd = xmkstemp(tmpname);
|
|
||||||
pack_tmp_name = xstrdup(tmpname);
|
pack_tmp_name = xstrdup(tmpname);
|
||||||
f = sha1fd(fd, pack_tmp_name);
|
f = sha1fd(fd, pack_tmp_name);
|
||||||
}
|
}
|
||||||
|
@ -817,9 +817,8 @@ static void start_packfile(void)
|
|||||||
struct pack_header hdr;
|
struct pack_header hdr;
|
||||||
int pack_fd;
|
int pack_fd;
|
||||||
|
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
pack_fd = odb_mkstemp(tmpfile, sizeof(tmpfile),
|
||||||
"%s/pack/tmp_pack_XXXXXX", get_object_directory());
|
"pack/tmp_pack_XXXXXX");
|
||||||
pack_fd = xmkstemp(tmpfile);
|
|
||||||
p = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);
|
p = xcalloc(1, sizeof(*p) + strlen(tmpfile) + 2);
|
||||||
strcpy(p->pack_name, tmpfile);
|
strcpy(p->pack_name, tmpfile);
|
||||||
p->pack_fd = pack_fd;
|
p->pack_fd = pack_fd;
|
||||||
@ -879,9 +878,8 @@ static char *create_index(void)
|
|||||||
c = next;
|
c = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
idx_fd = odb_mkstemp(tmpfile, sizeof(tmpfile),
|
||||||
"%s/pack/tmp_idx_XXXXXX", get_object_directory());
|
"pack/tmp_idx_XXXXXX");
|
||||||
idx_fd = xmkstemp(tmpfile);
|
|
||||||
f = sha1fd(idx_fd, tmpfile);
|
f = sha1fd(idx_fd, tmpfile);
|
||||||
sha1write(f, array, 256 * sizeof(int));
|
sha1write(f, array, 256 * sizeof(int));
|
||||||
git_SHA1_Init(&ctx);
|
git_SHA1_Init(&ctx);
|
||||||
@ -907,9 +905,7 @@ static char *keep_pack(char *curr_index_name)
|
|||||||
chmod(pack_data->pack_name, 0444);
|
chmod(pack_data->pack_name, 0444);
|
||||||
chmod(curr_index_name, 0444);
|
chmod(curr_index_name, 0444);
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "%s/pack/pack-%s.keep",
|
keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1);
|
||||||
get_object_directory(), sha1_to_hex(pack_data->sha1));
|
|
||||||
keep_fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
|
||||||
if (keep_fd < 0)
|
if (keep_fd < 0)
|
||||||
die("cannot create keep file");
|
die("cannot create keep file");
|
||||||
write_or_die(keep_fd, keep_msg, strlen(keep_msg));
|
write_or_die(keep_fd, keep_msg, strlen(keep_msg));
|
||||||
|
@ -303,6 +303,8 @@ extern ssize_t xwrite(int fd, const void *buf, size_t len);
|
|||||||
extern int xdup(int fd);
|
extern int xdup(int fd);
|
||||||
extern FILE *xfdopen(int fd, const char *mode);
|
extern FILE *xfdopen(int fd, const char *mode);
|
||||||
extern int xmkstemp(char *template);
|
extern int xmkstemp(char *template);
|
||||||
|
extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
|
||||||
|
extern int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1);
|
||||||
|
|
||||||
static inline size_t xsize_t(off_t len)
|
static inline size_t xsize_t(off_t len)
|
||||||
{
|
{
|
||||||
|
21
index-pack.c
21
index-pack.c
@ -172,9 +172,8 @@ static char *open_pack_file(char *pack_name)
|
|||||||
input_fd = 0;
|
input_fd = 0;
|
||||||
if (!pack_name) {
|
if (!pack_name) {
|
||||||
static char tmpfile[PATH_MAX];
|
static char tmpfile[PATH_MAX];
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
output_fd = odb_mkstemp(tmpfile, sizeof(tmpfile),
|
||||||
"%s/pack/tmp_pack_XXXXXX", get_object_directory());
|
"pack/tmp_pack_XXXXXX");
|
||||||
output_fd = xmkstemp(tmpfile);
|
|
||||||
pack_name = xstrdup(tmpfile);
|
pack_name = xstrdup(tmpfile);
|
||||||
} else
|
} else
|
||||||
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
|
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
|
||||||
@ -794,22 +793,24 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
|
|||||||
|
|
||||||
if (keep_msg) {
|
if (keep_msg) {
|
||||||
int keep_fd, keep_msg_len = strlen(keep_msg);
|
int keep_fd, keep_msg_len = strlen(keep_msg);
|
||||||
if (!keep_name) {
|
|
||||||
snprintf(name, sizeof(name), "%s/pack/pack-%s.keep",
|
if (!keep_name)
|
||||||
get_object_directory(), sha1_to_hex(sha1));
|
keep_fd = odb_pack_keep(name, sizeof(name), sha1);
|
||||||
keep_name = name;
|
else
|
||||||
}
|
|
||||||
keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);
|
||||||
|
|
||||||
if (keep_fd < 0) {
|
if (keep_fd < 0) {
|
||||||
if (errno != EEXIST)
|
if (errno != EEXIST)
|
||||||
die("cannot write keep file");
|
die("cannot write keep file '%s' (%s)",
|
||||||
|
keep_name, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
if (keep_msg_len > 0) {
|
if (keep_msg_len > 0) {
|
||||||
write_or_die(keep_fd, keep_msg, keep_msg_len);
|
write_or_die(keep_fd, keep_msg, keep_msg_len);
|
||||||
write_or_die(keep_fd, "\n", 1);
|
write_or_die(keep_fd, "\n", 1);
|
||||||
}
|
}
|
||||||
if (close(keep_fd) != 0)
|
if (close(keep_fd) != 0)
|
||||||
die("cannot write keep file");
|
die("cannot close written keep file '%s' (%s)",
|
||||||
|
keep_name, strerror(errno));
|
||||||
report = "keep";
|
report = "keep";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
|
|||||||
|
|
||||||
if (!index_name) {
|
if (!index_name) {
|
||||||
static char tmpfile[PATH_MAX];
|
static char tmpfile[PATH_MAX];
|
||||||
snprintf(tmpfile, sizeof(tmpfile),
|
fd = odb_mkstemp(tmpfile, sizeof(tmpfile), "pack/tmp_idx_XXXXXX");
|
||||||
"%s/pack/tmp_idx_XXXXXX", get_object_directory());
|
|
||||||
fd = xmkstemp(tmpfile);
|
|
||||||
index_name = xstrdup(tmpfile);
|
index_name = xstrdup(tmpfile);
|
||||||
} else {
|
} else {
|
||||||
unlink(index_name);
|
unlink(index_name);
|
||||||
@ -239,7 +237,7 @@ char *index_pack_lockfile(int ip_out)
|
|||||||
char packname[46];
|
char packname[46];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The first thing we expects from index-pack's output
|
* The first thing we expect from index-pack's output
|
||||||
* is "pack\t%40s\n" or "keep\t%40s\n" (46 bytes) where
|
* is "pack\t%40s\n" or "keep\t%40s\n" (46 bytes) where
|
||||||
* %40s is the newly created pack SHA1 name. In the "keep"
|
* %40s is the newly created pack SHA1 name. In the "keep"
|
||||||
* case, we need it to remove the corresponding .keep file
|
* case, we need it to remove the corresponding .keep file
|
||||||
|
@ -180,6 +180,23 @@ test_expect_success \
|
|||||||
|
|
||||||
unset GIT_OBJECT_DIRECTORY
|
unset GIT_OBJECT_DIRECTORY
|
||||||
|
|
||||||
|
test_expect_success 'survive missing objects/pack directory' '
|
||||||
|
(
|
||||||
|
rm -fr missing-pack &&
|
||||||
|
mkdir missing-pack &&
|
||||||
|
cd missing-pack &&
|
||||||
|
git init &&
|
||||||
|
GOP=.git/objects/pack
|
||||||
|
rm -fr $GOP &&
|
||||||
|
git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
|
||||||
|
test -f $GOP/pack-${packname_3}.pack &&
|
||||||
|
test_cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
|
||||||
|
test -f $GOP/pack-${packname_3}.idx &&
|
||||||
|
test_cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
|
||||||
|
test -f $GOP/pack-${packname_3}.keep
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'verify pack' \
|
'verify pack' \
|
||||||
'git verify-pack test-1-${packname_1}.idx \
|
'git verify-pack test-1-${packname_1}.idx \
|
||||||
|
32
wrapper.c
32
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");
|
error("inflate: %s (%s)", err, strm->msg ? strm->msg : "no message");
|
||||||
return ret;
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user