From ff61d9fc99a60a7c0320538a278d5f58680e120d Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 29 Dec 2006 09:03:45 +0100 Subject: [PATCH] Work around missing EISDIR errno values. Windows does not return EISDIR when a directory is opened as file. These instances are detected by checking explicitly whether the offending file is indeed a directory, and then the errno value is adjusted accordingly. --- refs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/refs.c b/refs.c index 1c0bf70f2c..f48045c5c9 100644 --- a/refs.c +++ b/refs.c @@ -838,6 +838,15 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg) retry: if (log && rename(git_path("tmp-renamed-log"), git_path("logs/%s", newref))) { +#ifdef __MINGW32__ + if (errno == EEXIST) { + struct stat st; + if (stat(git_path("logs/%s", newref), &st) == 0 && S_ISDIR(st.st_mode)) + errno = EISDIR; + else + errno = EEXIST; + } +#endif if (errno==EISDIR || errno==ENOTDIR) { /* * rename(a, b) when b is an existing @@ -946,6 +955,15 @@ static int log_ref_write(struct ref_lock *lock, if (!(oflags & O_CREAT) && errno == ENOENT) return 0; +#ifdef __MINGW32__ + if ((oflags & O_CREAT) && errno == EACCES) { + struct stat st; + if (stat(lock->log_file, &st) == 0 && S_ISDIR(st.st_mode)) + errno = EISDIR; + else + errno = EACCES; + } +#endif if ((oflags & O_CREAT) && errno == EISDIR) { if (remove_empty_directories(lock->log_file)) { return error("There are still logs under '%s'",