From a211fe1bbcb8e160136f3dd22b516ba751d4b02e Mon Sep 17 00:00:00 2001 From: Jose Date: Tue, 15 Mar 2016 10:14:53 +0100 Subject: ICE-7019 - remove db tools dependency on IcePatch2 --- cpp/src/IceUtil/FileUtil.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'cpp/src/IceUtil/FileUtil.cpp') diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp index ea7fc606e65..dfcbf670b5c 100644 --- a/cpp/src/IceUtil/FileUtil.cpp +++ b/cpp/src/IceUtil/FileUtil.cpp @@ -17,8 +17,12 @@ #ifdef _WIN32 # include # include +# ifndef ICE_OS_WINRT +# include +# endif #else # include +# include #endif using namespace std; @@ -89,6 +93,41 @@ IceUtilInternal::directoryExists(const string& path) return true; } +// +// Determinte if a directory exists and is empty +// +#ifndef ICE_OS_WINRT +bool +IceUtilInternal::isEmptyDirectory(const string& path) +{ +# ifdef _WIN32 + return PathIsDirectoryEmptyW(IceUtil::stringToWstring(path, IceUtil::getProcessStringConverter()).c_str()); +# else + struct dirent* d; + DIR* dir = opendir(path.c_str()); + if(dir) + { + bool empty = true; + while((d = readdir(dir))) + { + string name(d->d_name); + if(name != "." && name != "..") + { + empty = false; + break; + } + } + closedir(dir); + return empty; + } + else + { + return false; + } +# endif +} +#endif + // // Determine if a regular file exists. // -- cgit v1.2.3 From ebf507c026e5a4d640aede9bde1bc2fc5d4e0cdc Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Tue, 15 Mar 2016 15:37:37 -0700 Subject: minor comment fix in IceUtil --- cpp/src/IceUtil/FileUtil.cpp | 2 +- cpp/src/IceUtil/FileUtil.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'cpp/src/IceUtil/FileUtil.cpp') diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp index dfcbf670b5c..4e3dc407804 100644 --- a/cpp/src/IceUtil/FileUtil.cpp +++ b/cpp/src/IceUtil/FileUtil.cpp @@ -94,7 +94,7 @@ IceUtilInternal::directoryExists(const string& path) } // -// Determinte if a directory exists and is empty +// Determine if a directory exists and is empty. // #ifndef ICE_OS_WINRT bool diff --git a/cpp/src/IceUtil/FileUtil.h b/cpp/src/IceUtil/FileUtil.h index 8ff6af42406..7d5c478834d 100644 --- a/cpp/src/IceUtil/FileUtil.h +++ b/cpp/src/IceUtil/FileUtil.h @@ -41,7 +41,7 @@ ICE_UTIL_API bool fileExists(const std::string&); ICE_UTIL_API bool directoryExists(const std::string&); // -// Determinte if a directory exists and is empty +// Determine if a directory exists and is empty. // ICE_UTIL_API bool isEmptyDirectory(const std::string&); -- cgit v1.2.3