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

Skip to content

Commit 987ab76

Browse files
author
Vicent Martí
committed
Merge pull request libgit2#1634 from arrbee/alternative-mkdir-fix
Ensure git_futils_mkdir won't mkdir root
2 parents e236b37 + b832ecf commit 987ab76

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/fileops.c

Lines changed: 14 additions & 13 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, tmp_errno;
280+
int error = -1, tmp;
281281
git_buf make_path = GIT_BUF_INIT;
282282
ssize_t root = 0;
283283
char lastch, *tail;
@@ -315,6 +315,11 @@ int git_futils_mkdir(
315315
if (root < 0)
316316
root = 0;
317317

318+
/* make sure mkdir root is at least after filesystem root */
319+
tmp = git_path_root(make_path.ptr);
320+
if (root < tmp)
321+
root = tmp;
322+
318323
tail = & make_path.ptr[root];
319324

320325
while (*tail) {
@@ -345,26 +350,22 @@ int git_futils_mkdir(
345350

346351
already_exists = 1;
347352
break;
348-
#ifdef GIT_WIN32
349-
case EACCES:
350-
#endif
351353
case ENOSYS:
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
358-
* the definition of the error, so let's recheck */
359-
tmp_errno = errno;
354+
case EACCES:
355+
/* Possible recoverable errors. These errors could occur
356+
* on some OS if we try to mkdir at a network mount point
357+
* or at the root of a volume. If the path is a dir, just
358+
* treat as EEXIST.
359+
*/
360+
tmp = errno;
360361

361362
if (git_path_isdir(make_path.ptr)) {
362363
already_exists = 1;
363364
break;
364365
}
365366

366367
/* Fall through */
367-
errno = tmp_errno;
368+
errno = tmp;
368369
default:
369370
giterr_set(GITERR_OS, "Failed to make directory '%s'",
370371
make_path.ptr);

0 commit comments

Comments
 (0)