summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-10-11 11:23:34 -0400
committerEdward Thomson <ethomson@microsoft.com>2014-10-13 10:58:05 -0400
commit969b6a4710451b3e905757093dce4977cd596635 (patch)
tree763249f70afff01ccddee020c6615bb1e5fad7d0
parent8d45b4691c81d2d1cde7a1b2f828dedd55315b3f (diff)
downloadlibgit2-969b6a4710451b3e905757093dce4977cd596635.tar.gz
is_empty_dir (wi32): cope with empty mount points
FindFirstFile will fail with INVALID_HANDLE_VALUE if there are no children to the given path, which can happen if the given path is a file (and obviously has no children) or if the given path is an empty mount point. (Most directories have at least directory entries '.' and '..', but ridiculously another volume mounted in another drive letter's path space do not, and thus have nothing to enumerate.) If FindFirstFile fails, check if this is a directory-like thing (a mount point).
-rw-r--r--src/path.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/path.c b/src/path.c
index 21b6e18d6..143c564e8 100644
--- a/src/path.c
+++ b/src/path.c
@@ -515,23 +515,33 @@ bool git_path_is_empty_dir(const char *path)
WIN32_FIND_DATAW findData;
HANDLE hFind = FindFirstFileW(filter_w, &findData);
+ /* FindFirstFile will fail if there are no children to the given
+ * path, which can happen if the given path is a file (and obviously
+ * has no children) or if the given path is an empty mount point.
+ * (Most directories have at least directory entries '.' and '..',
+ * but ridiculously another volume mounted in another drive letter's
+ * path space do not, and thus have nothing to enumerate.) If
+ * FindFirstFile fails, check if this is a directory-like thing
+ * (a mount point).
+ */
+ if (hFind == INVALID_HANDLE_VALUE)
+ return git_path_isdir(path);
+
/* 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);
- }
+ 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);
}
return empty;