From: Linus Torvalds Date: Thu, 14 Jul 2005 00:27:48 +0000 (-0700) Subject: Make "git-checkout" create files with O_EXCL X-Git-Tag: v0.99.1~42 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2408cff9f738459019709c8c12d0bd8a5605566f;p=git.git Make "git-checkout" create files with O_EXCL 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. --- diff --git a/entry.c b/entry.c index ded83103..792ea733 100644 --- a/entry.c +++ b/entry.c @@ -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;