Skip to content

Commit

Permalink
Make "git-checkout" create files with O_EXCL
Browse files Browse the repository at this point in the history
We should always have unlinked any old ones before, but this just makes
sure that we never over-write any old file.

A quick "grep" now shows that all the core tools that open files for
writing use O_EXCL, ie we never overwrite an existing file in place.
  • Loading branch information
Linus Torvalds committed Jul 14, 2005
1 parent 1b66834 commit 2408cff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ static int create_file(const char *path, unsigned int mode, int force)
int fd;

mode = (mode & 0100) ? 0777 : 0666;
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT | O_EXCL, mode);
if (fd < 0) {
if (errno == EISDIR && force) {
remove_subtree(path);
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT | O_EXCL, mode);
}
}
return fd;
Expand Down

0 comments on commit 2408cff

Please sign in to comment.