提交 756aaf4a 编写于 作者: S Shawn Pearce 提交者: Junio C Hamano

Make lazy mkdir more robust.

Linus Torvalds <torvalds@osdl.org> wrote:

  It's entirely possible that we should just make that whole

	  if (ret == ENOENT)

  go away. Yes, it's the right error code if a subdirectory is missing, and
  yes, POSIX requires it, and yes, WXP is probably just a horrible piece of
  sh*t, but on the other hand, I don't think git really has any serious
  reason to even care.
上级 d3ba675a
......@@ -1331,31 +1331,29 @@ char *write_sha1_file_prepare(void *buf,
static int link_temp_to_file(const char *tmpfile, char *filename)
{
int ret;
char *dir;
if (!link(tmpfile, filename))
return 0;
/*
* Try to mkdir the last path component if that failed
* with an ENOENT.
* Try to mkdir the last path component if that failed.
*
* Re-try the "link()" regardless of whether the mkdir
* succeeds, since a race might mean that somebody
* else succeeded.
*/
ret = errno;
if (ret == ENOENT) {
char *dir = strrchr(filename, '/');
if (dir) {
*dir = 0;
mkdir(filename, 0777);
if (adjust_shared_perm(filename))
return -2;
*dir = '/';
if (!link(tmpfile, filename))
return 0;
ret = errno;
}
dir = strrchr(filename, '/');
if (dir) {
*dir = 0;
mkdir(filename, 0777);
if (adjust_shared_perm(filename))
return -2;
*dir = '/';
if (!link(tmpfile, filename))
return 0;
ret = errno;
}
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册