summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-07-04 21:33:26 +0200
committerVicent Marti <tanoku@gmail.com>2011-07-04 21:33:26 +0200
commitd3789825d3823bdbbebe278172345243618ca541 (patch)
tree6d7a528c92076ca443e2ae226134dd1f40a642fa /src/fileops.c
parent843d01d27f4372de24b3255146cf0fda70b850c1 (diff)
downloadlibgit2-fileops.tar.gz
fileops: Fix stat() on directories for W32fileops
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 275934ca1..fa45fde96 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -93,31 +93,20 @@ int git_futils_creat_locked_withpath(const char *path, int mode)
int git_futils_isdir(const char *path)
{
- struct stat st;
- int len, stat_error;
-
- assert(path);
-
- 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 = p_stat(path_fixed, &st);
- free(path_fixed);
- } else {
- stat_error = p_stat(path, &st);
- }
-
- if (stat_error < GIT_SUCCESS)
+#ifdef GIT_WIN32
+ DWORD attr = GetFileAttributes(path);
+ if (attr == INVALID_FILE_ATTRIBUTES)
return GIT_ERROR;
- if (!S_ISDIR(st.st_mode))
+ return (attr & FILE_ATTRIBUTE_DIRECTORY) ? GIT_SUCCESS : GIT_ERROR;
+
+#else
+ struct stat st;
+ if (p_stat(path, &st) < GIT_SUCCESS)
return GIT_ERROR;
- return GIT_SUCCESS;
+ return S_ISDIR(st.st_mode) ? GIT_SUCCESS : GIT_ERROR;
+#endif
}
int git_futils_isfile(const char *path)