From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] Set errno to EEXIST if mkdir returns EACCES or EPERM
Date: Mon, 30 Jan 2006 20:38:39 +0100 [thread overview]
Message-ID: <20060130193839.GA6575@steel.home> (raw)
... and the directory already exists. I.E. Cygwin is such
a case: mkdir fail for mounts which reference directly
to windows mounts ("drives").
---
The discussion, which ended up with this patch can be read
here: http://www.cygwin.com/ml/cygwin/2006-01/msg01276.html
BTW, there is this:
http://www.cygwin.com/ml/cygwin/2006-01/msg01380.html
So this patch will probably be not needed soon.
Still I post it just for reference, or in case someone
can't afford an upgrade.
Makefile | 8 ++++++++
checkout-index.c | 2 +-
compat/mkdir.c | 23 +++++++++++++++++++++++
git-compat-util.h | 6 ++++++
4 files changed, 38 insertions(+), 1 deletions(-)
create mode 100644 compat/mkdir.c
c9f480f5d1e777cc0f4861e94c2449bd8c7cf73a
diff --git a/Makefile b/Makefile
index 2e95353..596c2d8 100644
--- a/Makefile
+++ b/Makefile
@@ -66,6 +66,9 @@ all:
# Define USE_STDEV below if you want git to care about the underlying device
# change being considered an inode change from the update-cache perspective.
+# Define FIX_MKDIR_ERRNO if your mkdir(2) does not always set errno to EEXIST
+# if it failed because of existing directory (notably Cygwin).
+
GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
@$(SHELL) ./GIT-VERSION-GEN
-include GIT-VERSION-FILE
@@ -249,6 +252,7 @@ ifeq ($(uname_O),Cygwin)
# Try uncommenting this if you see things break -- YMMV.
# NO_MMAP = YesPlease
NO_IPV6 = YesPlease
+ FIX_MKDIR_ERRNO = YesPlease
X = .exe
endif
ifeq ($(uname_S),OpenBSD)
@@ -392,6 +396,10 @@ else
endif
endif
endif
+ifdef FIX_MKDIR_ERRNO
+ COMPAT_CFLAGS += -DFIX_MKDIR_ERRNO
+ COMPAT_OBJS += compat/mkdir.o
+endif
ALL_CFLAGS += -DSHA1_HEADER=$(call shellquote,$(SHA1_HEADER)) $(COMPAT_CFLAGS)
LIB_OBJS += $(COMPAT_OBJS)
diff --git a/checkout-index.c b/checkout-index.c
index 53dd8cb..c5a6d6e 100644
--- a/checkout-index.c
+++ b/checkout-index.c
@@ -199,6 +199,6 @@ int main(int argc, char **argv)
if (0 <= newfd &&
(write_cache(newfd, active_cache, active_nr) ||
commit_index_file(&cache_file)))
- die("Unable to write new cachefile");
+ die("Unable to write new cachefile: %s", strerror(errno));
return 0;
}
diff --git a/compat/mkdir.c b/compat/mkdir.c
new file mode 100644
index 0000000..1c2260c
--- /dev/null
+++ b/compat/mkdir.c
@@ -0,0 +1,23 @@
+#include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include "../git-compat-util.h"
+#undef mkdir
+
+int gitmkdir(const char *dir, mode_t mode)
+{
+ int rc = mkdir(dir, mode);
+ if ( rc < 0 ) {
+ int e = errno;
+ if ( EACCES == e || EPERM == e )
+ {
+ struct stat st;
+ if ( stat(dir, &st) == 0 )
+ errno = EEXIST;
+ else
+ errno = e;
+ }
+ }
+ return rc;
+}
+
diff --git a/git-compat-util.h b/git-compat-util.h
index f982b8e..9cf3aab 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -154,4 +154,10 @@ static inline int sane_case(int x, int h
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif
+
+#ifdef FIX_MKDIR_ERRNO
+#define mkdir gitmkdir
+int gitmkdir(const char *dir, mode_t mode);
+#endif
+
#endif
--
1.1.4.g7397-dirty
next reply other threads:[~2006-01-30 19:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-30 19:38 Alex Riesen [this message]
2006-01-30 20:33 ` [PATCH] Set errno to EEXIST if mkdir returns EACCES or EPERM Junio C Hamano
2006-01-30 23:16 ` Alex Riesen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060130193839.GA6575@steel.home \
--to=raa.lkml@gmail.com \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).