提交 2408cff9 编写于 作者: L Linus Torvalds

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.
上级 1b668341
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册