diff options
| author | Vicent Marti <tanoku@gmail.com> | 2010-11-23 15:18:53 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2010-11-24 00:23:15 +0200 |
| commit | 43e380a88ceb0eb5d1b94f2e5736bc7e8e4f4176 (patch) | |
| tree | 86f19bf973b10e6d5338f361dfb192c2f0569d80 /src | |
| parent | 6b1eab3976b5b7cf4e65b9d12e5e25a98411c4da (diff) | |
| download | libgit2-43e380a88ceb0eb5d1b94f2e5736bc7e8e4f4176.tar.gz | |
Fix gitfo_isdir() in Win32 systems
Because adhering to the POSIX standards is overrated.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/fileops.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/fileops.c b/src/fileops.c index e0a5ff461..210e7d6e7 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -56,7 +56,25 @@ int gitfo_write(git_file fd, void *buf, size_t cnt) int gitfo_isdir(const char *path) { struct stat st; - return (path && gitfo_stat(path, &st) == 0 && S_ISDIR(st.st_mode)) ? + int len, stat_error; + + if (!path) + return GIT_ENOTFOUND; + + len = strlen(path); + + /* win32: stat path for folders cannot end in a slash */ + if (path[len - 1] == '/') { + char *path_fixed = NULL; + path_fixed = git__strdup(path); + path_fixed[len - 1] = 0; + stat_error = gitfo_stat(path_fixed, &st); + free(path_fixed); + } else { + stat_error = gitfo_stat(path, &st); + } + + return (stat_error == 0 && S_ISDIR(st.st_mode)) ? GIT_SUCCESS : GIT_ENOTFOUND; } |
