Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bstraub@github.com>2012-07-11 21:40:53 +0400
committerBen Straub <bstraub@github.com>2012-07-11 21:40:53 +0400
commitd024419f165e81f59d919bd56d84abf8e9fb9f57 (patch)
tree93c6fe213a8249c8308a3ee607da6af769125d55 /src/path.c
parentc3b5099fe46e1191784cc1890cd35f167305f47a (diff)
Add git_path_is_empty_dir.
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/path.c b/src/path.c
index 3de4b1100..e667ec357 100644
--- a/src/path.c
+++ b/src/path.c
@@ -389,6 +389,58 @@ bool git_path_isfile(const char *path)
return S_ISREG(st.st_mode) != 0;
}
+#ifdef GIT_WIN32
+
+bool git_path_is_empty_dir(const char *path)
+{
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ wchar_t *wbuf;
+ WIN32_FIND_DATAW ffd;
+ bool retval = true;
+
+ if (!git_path_isdir(path)) return false;
+
+ wbuf = gitwin_to_utf16(path);
+ gitwin_append_utf16(wbuf, "\\*", 2);
+ hFind = FindFirstFileW(wbuf, &ffd);
+ if (INVALID_HANDLE_VALUE != hFind) {
+ retval = false;
+ FindClose(hFind);
+ }
+ git__free(wbuf);
+ return retval;
+}
+
+#else
+
+bool git_path_is_empty_dir(const char *path)
+{
+ DIR *dir = NULL;
+ struct dirent *e;
+ bool retval = true;
+
+ if (!git_path_isdir(path)) return false;
+
+ dir = opendir(path);
+ if (!dir) {
+ giterr_set(GITERR_OS, "Couldn't open '%s'", path);
+ return false;
+ }
+
+ while ((e = readdir(dir)) != NULL) {
+ if (!git_path_is_dot_or_dotdot(e->d_name)) {
+ giterr_set(GITERR_INVALID,
+ "'%s' exists and is not an empty directory", path);
+ retval = false;
+ break;
+ }
+ }
+ closedir(dir);
+
+ return retval;
+}
+#endif
+
int git_path_lstat(const char *path, struct stat *st)
{
int err = 0;