Code

Make "git-checkout" create files with O_EXCL
[git.git] / entry.c
diff --git a/entry.c b/entry.c
index ded83103a9d8f16333d941e1e5410e0a12822ae7..792ea733e851a3d288cad1e34ea89478503e71be 100644 (file)
--- 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;