From 414ffcbc35b71271cb52d533c4c5617db8616c22 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Thu, 21 May 2020 18:42:42 +0200 Subject: [PATCH] #688: always using dirbrowser snapshot to fix issues with leftovers on cleanup --- config.h.in | 4 -- configure | 14 ------ configure.ac | 12 ------ daemon/util/FileSystem.cpp | 87 +++++++++++++++----------------------- daemon/util/FileSystem.h | 6 --- 5 files changed, 33 insertions(+), 90 deletions(-) diff --git a/config.h.in b/config.h.in index f1d49937..b757759c 100644 --- a/config.h.in +++ b/config.h.in @@ -3,10 +3,6 @@ /* Define to 1 to include debug-code */ #undef DEBUG -/* Define to 1 if deleting of files during reading of directory is not - properly supported by OS */ -#undef DIRBROWSER_SNAPSHOT - /* Define to 1 to not use curses */ #undef DISABLE_CURSES diff --git a/configure b/configure index ad26e189..eb060df3 100755 --- a/configure +++ b/configure @@ -6611,20 +6611,6 @@ _ACEOF -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether dir-browser snapshot workaround is needed" >&5 -$as_echo_n "checking whether dir-browser snapshot workaround is needed... " >&6; } -if test "$target_vendor" == "apple"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -$as_echo "#define DIRBROWSER_SNAPSHOT 1" >>confdefs.h - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cpu cores via sysconf" >&5 $as_echo_n "checking for cpu cores via sysconf... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext diff --git a/configure.ac b/configure.ac index 2745362c..d7bd51bb 100644 --- a/configure.ac +++ b/configure.ac @@ -222,18 +222,6 @@ AC_TRY_COMPILE([ AC_DEFINE_UNQUOTED(SOCKLEN_T, $SOCKLEN_T, [Determine what socket length (socklen_t) data type is]) -dnl -dnl Dir-browser's snapshot -dnl -AC_MSG_CHECKING(whether dir-browser snapshot workaround is needed) -if test "$target_vendor" == "apple"; then - AC_MSG_RESULT([[yes]]) - AC_DEFINE([DIRBROWSER_SNAPSHOT], 1, [Define to 1 if deleting of files during reading of directory is not properly supported by OS]) -else - AC_MSG_RESULT([[no]]) -fi - - dnl dnl check cpu cores via sysconf dnl diff --git a/daemon/util/FileSystem.cpp b/daemon/util/FileSystem.cpp index 99099826..c0ca4c4c 100644 --- a/daemon/util/FileSystem.cpp +++ b/daemon/util/FileSystem.cpp @@ -1020,52 +1020,9 @@ CString FileSystem::WidePathToUtfPath(const wchar_t* wpath) #endif -#ifdef WIN32 -DirBrowser::DirBrowser(const char* path) -{ - BString<1024> mask("%s%c*.*", path, PATH_SEPARATOR); - m_file = FindFirstFileW(FileSystem::UtfPathToWidePath(mask), &m_findData); - m_first = true; -} - -DirBrowser::~DirBrowser() -{ - if (m_file != INVALID_HANDLE_VALUE) - { - FindClose(m_file); - } -} - -const char* DirBrowser::InternNext() -{ - bool ok = false; - if (m_first) - { - ok = m_file != INVALID_HANDLE_VALUE; - m_first = false; - } - else - { - ok = FindNextFileW(m_file, &m_findData) != 0; - } - if (ok) - { - m_filename = FileSystem::WidePathToUtfPath(m_findData.cFileName); - return m_filename; - } - return nullptr; -} - -#else - -#ifdef DIRBROWSER_SNAPSHOT DirBrowser::DirBrowser(const char* path, bool snapshot) : m_snapshot(snapshot) -#else -DirBrowser::DirBrowser(const char* path) -#endif { -#ifdef DIRBROWSER_SNAPSHOT if (m_snapshot) { DirBrowser dir(path, false); @@ -1076,35 +1033,57 @@ DirBrowser::DirBrowser(const char* path) m_snapshotIter = m_snapshotFiles.begin(); } else -#endif { +#ifdef WIN32 + BString<1024> mask("%s%c*.*", path, PATH_SEPARATOR); + m_file = FindFirstFileW(FileSystem::UtfPathToWidePath(mask), &m_findData); + m_first = true; +#else m_dir = opendir(path); +#endif } } DirBrowser::~DirBrowser() { -#ifdef DIRBROWSER_SNAPSHOT - if (!m_snapshot) -#endif +#ifdef WIN32 + if (m_file != INVALID_HANDLE_VALUE) { - if (m_dir) - { - closedir(m_dir); - } + FindClose(m_file); } +#else + if (m_dir) + { + closedir(m_dir); + } +#endif } const char* DirBrowser::InternNext() { -#ifdef DIRBROWSER_SNAPSHOT if (m_snapshot) { return m_snapshotIter == m_snapshotFiles.end() ? nullptr : **m_snapshotIter++; } else -#endif { +#ifdef WIN32 + bool ok = false; + if (m_first) + { + ok = m_file != INVALID_HANDLE_VALUE; + m_first = false; + } + else + { + ok = FindNextFileW(m_file, &m_findData) != 0; + } + if (ok) + { + m_filename = FileSystem::WidePathToUtfPath(m_findData.cFileName); + return m_filename; + } +#else if (m_dir) { m_findData = readdir(m_dir); @@ -1113,10 +1092,10 @@ const char* DirBrowser::InternNext() return m_findData->d_name; } } +#endif return nullptr; } } -#endif const char* DirBrowser::Next() { diff --git a/daemon/util/FileSystem.h b/daemon/util/FileSystem.h index 60d62493..b2b19f00 100644 --- a/daemon/util/FileSystem.h +++ b/daemon/util/FileSystem.h @@ -84,11 +84,7 @@ public: class DirBrowser { public: -#ifdef DIRBROWSER_SNAPSHOT DirBrowser(const char* path, bool snapshot = true); -#else - DirBrowser(const char* path); -#endif ~DirBrowser(); const char* Next(); @@ -103,12 +99,10 @@ private: struct dirent* m_findData; #endif -#ifdef DIRBROWSER_SNAPSHOT bool m_snapshot; typedef std::deque FileList; FileList m_snapshotFiles; FileList::iterator m_snapshotIter; -#endif const char* InternNext(); };