Skip to content

Commit

Permalink
Fix 'quickfix' on pack-objects.
Browse files Browse the repository at this point in the history
The earlier quickfix forced world-readable permission bits.  This
updates it to honor umask and core.sharedrepository settings.

Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Apr 22, 2007
1 parent aef5aed commit b6b32cc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions builtin-pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,13 @@ static void get_object_list(int ac, const char **av)
traverse_commit_list(&revs, show_commit, show_object);
}

static int adjust_perm(const char *path, mode_t mode)
{
if (chmod(path, mode))
return -1;
return adjust_shared_perm(path);
}

int cmd_pack_objects(int argc, const char **argv, const char *prefix)
{
int depth = 10;
Expand Down Expand Up @@ -1780,18 +1787,23 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
last_obj_offset = write_pack_file();
if (!pack_to_stdout) {
unsigned char object_list_sha1[20];
mode_t mode = umask(0);

umask(mode);
mode = 0666 & ~mode;

write_index_file(last_obj_offset, object_list_sha1);
snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
base_name, sha1_to_hex(object_list_sha1));
if (chmod(pack_tmp_name, 0644))
if (adjust_perm(pack_tmp_name, mode))
die("unable to make temporary pack file readable: %s",
strerror(errno));
if (rename(pack_tmp_name, tmpname))
die("unable to rename temporary pack file: %s",
strerror(errno));
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
base_name, sha1_to_hex(object_list_sha1));
if (chmod(idx_tmp_name, 0644))
if (adjust_perm(idx_tmp_name, mode))
die("unable to make temporary index file readable: %s",
strerror(errno));
if (rename(idx_tmp_name, tmpname))
Expand Down

0 comments on commit b6b32cc

Please sign in to comment.