Commit 7d8e4e30 by Edward Thomson Committed by Carlos Martín Nieto

mkdir: respect the root path

Don't try to strip trailing paths from the root directory on
Windows (trying to create `C:` will fail).
parent 69455bc8
...@@ -330,7 +330,7 @@ int git_futils_mkdir_withperf( ...@@ -330,7 +330,7 @@ int git_futils_mkdir_withperf(
{ {
int error = -1; int error = -1;
git_buf make_path = GIT_BUF_INIT; git_buf make_path = GIT_BUF_INIT;
ssize_t root = 0, min_root_len; ssize_t root = 0, min_root_len, root_len;
char lastch = '/', *tail; char lastch = '/', *tail;
struct stat st; struct stat st;
...@@ -343,22 +343,29 @@ int git_futils_mkdir_withperf( ...@@ -343,22 +343,29 @@ int git_futils_mkdir_withperf(
goto done; goto done;
} }
/* remove trailing slashes on path */ /* Trim trailing slashes (except the root) */
while (make_path.ptr[make_path.size - 1] == '/') { if ((root_len = git_path_root(make_path.ptr)) < 0)
make_path.size--; root_len = 0;
make_path.ptr[make_path.size] = '\0'; else
} root_len++;
while (make_path.size > (size_t)root_len &&
make_path.ptr[make_path.size - 1] == '/')
make_path.ptr[--make_path.size] = '\0';
/* if we are not supposed to made the last element, truncate it */ /* if we are not supposed to made the last element, truncate it */
if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) { if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) {
git_buf_rtruncate_at_char(&make_path, '/'); git_path_dirname_r(&make_path, make_path.ptr);
flags |= GIT_MKDIR_SKIP_LAST; flags |= GIT_MKDIR_SKIP_LAST;
} }
if ((flags & GIT_MKDIR_SKIP_LAST) != 0) if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
git_buf_rtruncate_at_char(&make_path, '/'); git_path_dirname_r(&make_path, make_path.ptr);
}
/* if nothing left after truncation, then we're done! */ /* We were either given the root path (or trimmed it to
if (!make_path.size) { * the root), we don't have anything to do.
*/
if (make_path.size <= (size_t)root_len) {
error = 0; error = 0;
goto done; goto done;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment