Allow cloning to an existing empty directory
[gitweb.git] / dir.c
diff --git a/dir.c b/dir.c
index 3347f46bcf62ff6969efa36d44907f1097e758ce..7c598296a9e4997e153f4762b4a222328a6bd36b 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -777,6 +777,25 @@ int is_inside_dir(const char *dir)
        return get_relative_cwd(buffer, sizeof(buffer), dir) != NULL;
 }
 
+int is_empty_dir(const char *path)
+{
+       DIR *dir = opendir(path);
+       struct dirent *e;
+       int ret = 1;
+
+       if (!dir)
+               return 0;
+
+       while ((e = readdir(dir)) != NULL)
+               if (!is_dot_or_dotdot(e->d_name)) {
+                       ret = 0;
+                       break;
+               }
+
+       closedir(dir);
+       return ret;
+}
+
 int remove_dir_recursively(struct strbuf *path, int only_empty)
 {
        DIR *dir = opendir(path->buf);