diff options
author | Vicent Marti <vicent@github.com> | 2014-04-23 07:13:49 -0700 |
---|---|---|
committer | Vicent Marti <vicent@github.com> | 2014-04-23 07:13:49 -0700 |
commit | 5ca410b9a9bc30a65ed0125646b3702d5943100b (patch) | |
tree | 7c352c4382def6eaee007745f3f932659b10d827 /src/path.c | |
parent | 5b58d6f78cf8346445374eaf5cde0f54be5c5796 (diff) | |
parent | 7110000dd5b82c86863633ee37f72ac876a44476 (diff) | |
download | libgit2-5ca410b9a9bc30a65ed0125646b3702d5943100b.tar.gz |
Merge pull request #2283 from phkelley/win32_fs
Win32: UTF-8 <-> WCHAR conversion overhaul
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/path.c b/src/path.c index a990b005f..2690cd8e8 100644 --- a/src/path.c +++ b/src/path.c @@ -9,6 +9,7 @@ #include "posix.h" #ifdef GIT_WIN32 #include "win32/posix.h" +#include "win32/w32_util.h" #else #include <dirent.h> #endif @@ -486,33 +487,33 @@ bool git_path_isfile(const char *path) bool git_path_is_empty_dir(const char *path) { - HANDLE hFind = INVALID_HANDLE_VALUE; - git_win32_path wbuf; - int wbufsz; - WIN32_FIND_DATAW ffd; - bool retval = true; - - if (!git_path_isdir(path)) - return false; - - wbufsz = git_win32_path_from_c(wbuf, path); - if (!wbufsz || wbufsz + 2 > GIT_WIN_PATH_UTF16) - return false; - memcpy(&wbuf[wbufsz - 1], L"\\*", 3 * sizeof(wchar_t)); - - hFind = FindFirstFileW(wbuf, &ffd); - if (INVALID_HANDLE_VALUE == hFind) - return false; - - do { - if (!git_path_is_dot_or_dotdotW(ffd.cFileName)) { - retval = false; - break; + git_win32_path filter_w; + bool empty = false; + + if (git_win32__findfirstfile_filter(filter_w, path)) { + WIN32_FIND_DATAW findData; + HANDLE hFind = FindFirstFileW(filter_w, &findData); + + /* If the find handle was created successfully, then it's a directory */ + if (hFind != INVALID_HANDLE_VALUE) { + empty = true; + + do { + /* Allow the enumeration to return . and .. and still be considered + * empty. In the special case of drive roots (i.e. C:\) where . and + * .. do not occur, we can still consider the path to be an empty + * directory if there's nothing there. */ + if (!git_path_is_dot_or_dotdotW(findData.cFileName)) { + empty = false; + break; + } + } while (FindNextFileW(hFind, &findData)); + + FindClose(hFind); } - } while (FindNextFileW(hFind, &ffd) != 0); + } - FindClose(hFind); - return retval; + return empty; } #else |