mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-20 20:23:26 +00:00
Merge pull request #1634 from arrbee/alternative-mkdir-fix
Ensure git_futils_mkdir won't mkdir root
This commit is contained in:
commit
987ab76580
@ -277,7 +277,7 @@ int git_futils_mkdir(
|
|||||||
mode_t mode,
|
mode_t mode,
|
||||||
uint32_t flags)
|
uint32_t flags)
|
||||||
{
|
{
|
||||||
int error = -1, tmp_errno;
|
int error = -1, tmp;
|
||||||
git_buf make_path = GIT_BUF_INIT;
|
git_buf make_path = GIT_BUF_INIT;
|
||||||
ssize_t root = 0;
|
ssize_t root = 0;
|
||||||
char lastch, *tail;
|
char lastch, *tail;
|
||||||
@ -315,6 +315,11 @@ int git_futils_mkdir(
|
|||||||
if (root < 0)
|
if (root < 0)
|
||||||
root = 0;
|
root = 0;
|
||||||
|
|
||||||
|
/* make sure mkdir root is at least after filesystem root */
|
||||||
|
tmp = git_path_root(make_path.ptr);
|
||||||
|
if (root < tmp)
|
||||||
|
root = tmp;
|
||||||
|
|
||||||
tail = & make_path.ptr[root];
|
tail = & make_path.ptr[root];
|
||||||
|
|
||||||
while (*tail) {
|
while (*tail) {
|
||||||
@ -345,18 +350,14 @@ int git_futils_mkdir(
|
|||||||
|
|
||||||
already_exists = 1;
|
already_exists = 1;
|
||||||
break;
|
break;
|
||||||
#ifdef GIT_WIN32
|
|
||||||
case EACCES:
|
|
||||||
#endif
|
|
||||||
case ENOSYS:
|
case ENOSYS:
|
||||||
/* The following errors can be generated if:
|
case EACCES:
|
||||||
* EACCES - Win32 can generate this error if you try to mkdir
|
/* Possible recoverable errors. These errors could occur
|
||||||
* a path which is the root of a volume.
|
* on some OS if we try to mkdir at a network mount point
|
||||||
* ENOSYS - Solaris can generate a ENOSYS error if you try to mkdir
|
* or at the root of a volume. If the path is a dir, just
|
||||||
* a path which is already a mount point.
|
* treat as EEXIST.
|
||||||
* In these cases, the path does already exist; but it's not implied by
|
*/
|
||||||
* the definition of the error, so let's recheck */
|
tmp = errno;
|
||||||
tmp_errno = errno;
|
|
||||||
|
|
||||||
if (git_path_isdir(make_path.ptr)) {
|
if (git_path_isdir(make_path.ptr)) {
|
||||||
already_exists = 1;
|
already_exists = 1;
|
||||||
@ -364,7 +365,7 @@ int git_futils_mkdir(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
errno = tmp_errno;
|
errno = tmp;
|
||||||
default:
|
default:
|
||||||
giterr_set(GITERR_OS, "Failed to make directory '%s'",
|
giterr_set(GITERR_OS, "Failed to make directory '%s'",
|
||||||
make_path.ptr);
|
make_path.ptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user