1.1 --- a/libfsserver/lib/files/host_file_opener.cc Thu Feb 17 00:37:13 2022 +0100
1.2 +++ b/libfsserver/lib/files/host_file_opener.cc Thu Feb 17 19:41:23 2022 +0100
1.3 @@ -19,7 +19,9 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 +#include <dirent.h>
1.8 #include <stdio.h>
1.9 +#include <string.h>
1.10 #include <sys/stat.h>
1.11 #include <unistd.h>
1.12
1.13 @@ -69,6 +71,34 @@
1.14 return (st.st_mode & S_IFREG) ? true : false;
1.15 }
1.16
1.17 +/* Test if a directory is empty. */
1.18 +
1.19 +bool HostFileOpener::directory_is_empty(fileid_t fileid)
1.20 +{
1.21 + const char *path = _get_path(fileid);
1.22 +
1.23 + if (path == NULL)
1.24 + return false;
1.25 +
1.26 + DIR *dir = opendir(path);
1.27 + struct dirent *entry;
1.28 +
1.29 + if (dir == NULL)
1.30 + return false;
1.31 +
1.32 + while ((entry = readdir(dir)) != NULL)
1.33 + {
1.34 + if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
1.35 + {
1.36 + closedir(dir);
1.37 + return false;
1.38 + }
1.39 + }
1.40 +
1.41 + closedir(dir);
1.42 + return true;
1.43 +}
1.44 +
1.45 /* Return a file identifier for the given 'path'. */
1.46
1.47 long HostFileOpener::get_fileid(const char *path, flags_t flags, fileid_t *fileid)