Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-05 07:45:22 +0300
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-05 20:27:19 +0300
commit9cb5b0f73c610692cc62f6d98f527bf1ab326924 (patch)
tree23fe01f61e89a61b906c632285e2d23dca64b2ba /src/fileops.c
parent3c68bfcd088dd5a1ef06b98ea7fd203bb048fa42 (diff)
mkdir: respect the root path
Don't try to strip trailing paths from the root directory on Windows (trying to create `C:` will fail).
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 2ee9535be..4a62d210d 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -330,7 +330,7 @@ int git_futils_mkdir_withperf(
{
int error = -1;
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;
struct stat st;
@@ -343,22 +343,29 @@ int git_futils_mkdir_withperf(
goto done;
}
- /* remove trailing slashes on path */
- while (make_path.ptr[make_path.size - 1] == '/') {
- make_path.size--;
- make_path.ptr[make_path.size] = '\0';
- }
+ /* Trim trailing slashes (except the root) */
+ if ((root_len = git_path_root(make_path.ptr)) < 0)
+ root_len = 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 ((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;
}
- if ((flags & GIT_MKDIR_SKIP_LAST) != 0)
- git_buf_rtruncate_at_char(&make_path, '/');
+ if ((flags & GIT_MKDIR_SKIP_LAST) != 0) {
+ git_path_dirname_r(&make_path, make_path.ptr);
+ }
- /* if nothing left after truncation, then we're done! */
- if (!make_path.size) {
+ /* We were either given the root path (or trimmed it to
+ * the root), we don't have anything to do.
+ */
+ if (make_path.size <= (size_t)root_len) {
error = 0;
goto done;
}