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.
This commit is contained in:
Johannes Sixt
2006-12-29 09:03:45 +01:00
parent 2de27f2cbb
commit ff61d9fc99

18
refs.c
View File

@@ -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'",