Skip to content

Commit ea56518

Browse files
dschogitster
authored andcommitted
Handle more file writes correctly in shared repos
In shared repositories, we have to be careful when writing files whose permissions do not allow users other than the owner to write them. In particular, we force the marks file of fast-export and the FETCH_HEAD when fetching to be rewritten from scratch. This commit does not touch other calls to fopen() that want to write files: - commands that write to working tree files (core.sharedRepository does not affect permission bits of working tree files), e.g. .rej file created by "apply --reject", result of applying a previous conflict resolution by "rerere", "git merge-file". - git am, when splitting mails (git-am correctly cleans up its directory after finishing, so there is no need to share those files between users) - git submodule clone, when writing the .git file, because the file will not be overwritten - git_terminal_prompt() in compat/terminal.c, because it is not writing to a file at all - git diff --output, because the output file is clearly not intended to be shared between the users of the current repository - git fast-import, when writing a crash report, because the reports' file names are unique due to an embedded process ID - mailinfo() in mailinfo.c, because the output is clearly not intended to be shared between the users of the current repository - check_or_regenerate_marks() in remote-testsvn.c, because this is only used for Git's internal testing - git fsck, when writing lost&found blobs (this should probably be changed, but left as a low-hanging fruit for future contributors). Note that this patch does not touch callers of write_file() and write_file_gently(), which would benefit from the same scrutiny as to usage in shared repositories. Most notable users are branch, daemon, submodule & worktree, and a worrisome call in transport.c when updating one ref (which ignores the shared flag). Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 79d7582 commit ea56518

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ static void export_marks(char *file)
880880
FILE *f;
881881
int e = 0;
882882

883-
f = fopen(file, "w");
883+
f = fopen_for_writing(file);
884884
if (!f)
885885
die_errno("Unable to open marks file %s for writing.", file);
886886

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ static void check_not_current_branch(struct ref *ref_map)
836836
static int truncate_fetch_head(void)
837837
{
838838
const char *filename = git_path_fetch_head();
839-
FILE *fp = fopen(filename, "w");
839+
FILE *fp = fopen_for_writing(filename);
840840

841841
if (!fp)
842842
return error(_("cannot open %s: %s\n"), filename, strerror(errno));

0 commit comments

Comments
 (0)