Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daf98cb

Browse files
committed
Allow creation of directories under the volume root in Win32
We ran into an issue where cloning a repository to a folder directly underneath the root of a volume (e.g. 'd:\libgit2') would fail with an access denied error. This was traced down to a call to make a directory that is the root (e.g. 'd:') could return an error indicated access denied instead of an error indicating the path already exists. This change now handles the access denied error on Win32 and checks for the existence of the folder.
1 parent 9d9fff3 commit daf98cb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/fileops.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ int git_futils_mkdir(
277277
mode_t mode,
278278
uint32_t flags)
279279
{
280-
int error = -1;
280+
int error = -1, tmp_errno;
281281
git_buf make_path = GIT_BUF_INIT;
282282
ssize_t root = 0;
283283
char lastch, *tail;
@@ -345,18 +345,26 @@ int git_futils_mkdir(
345345

346346
already_exists = 1;
347347
break;
348+
#ifdef GIT_WIN32
349+
case EACCES:
350+
#endif
348351
case ENOSYS:
349-
/* Solaris can generate this error if you try to mkdir
350-
* a path which is already a mount point. In that case,
351-
* the path does already exist; but it's not implied by
352+
/* The following errors can be generated if:
353+
* EACCES - Win32 can generate this error if you try to mkdir
354+
* a path which is the root of a volume.
355+
* ENOSYS - Solaris can generate a ENOSYS error if you try to mkdir
356+
* a path which is already a mount point.
357+
* In these cases, the path does already exist; but it's not implied by
352358
* the definition of the error, so let's recheck */
359+
tmp_errno = errno;
360+
353361
if (git_path_isdir(make_path.ptr)) {
354362
already_exists = 1;
355363
break;
356364
}
357365

358366
/* Fall through */
359-
errno = ENOSYS;
367+
errno = tmp_errno;
360368
default:
361369
giterr_set(GITERR_OS, "Failed to make directory '%s'",
362370
make_path.ptr);

0 commit comments

Comments
 (0)