Skip to content

Commit 3c68bfc

Browse files
Edward Thomsonethomson
authored andcommitted
stat: don't remove trailing '/' from root on win32
`p_stat` calls `git_win32_path_from_utf8`, which canonicalizes the path. Do not further try to modify the path, else we trim the trailing slash from a root directory and try to access `C:` instead of `C:/`.
1 parent 2f4ee00 commit 3c68bfc

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/win32/posix_w32.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,8 @@ int p_stat(const char* path, struct stat* buf)
448448
git_win32_path path_w;
449449
int len;
450450

451-
if ((len = git_win32_path_from_utf8(path_w, path)) < 0)
452-
return -1;
453-
454-
git_win32__path_trim_end(path_w, len);
455-
456-
if (lstat_w(path_w, buf, false) < 0)
451+
if ((len = git_win32_path_from_utf8(path_w, path)) < 0 ||
452+
lstat_w(path_w, buf, false) < 0)
457453
return -1;
458454

459455
/* The item is a symbolic link or mount point. No need to iterate

tests/core/stat.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,20 @@ void test_core_stat__0(void)
9595
cl_assert_error(ENOTDIR);
9696
}
9797

98+
void test_core_stat__root(void)
99+
{
100+
const char *sandbox = clar_sandbox_path();
101+
git_buf root = GIT_BUF_INIT;
102+
int root_len;
103+
struct stat st;
104+
105+
root_len = git_path_root(sandbox);
106+
cl_assert(root_len >= 0);
107+
108+
git_buf_set(&root, sandbox, root_len+1);
109+
110+
cl_must_pass(p_stat(root.ptr, &st));
111+
cl_assert(S_ISDIR(st.st_mode));
112+
113+
git_buf_free(&root);
114+
}

0 commit comments

Comments
 (0)