diff --git a/libretroshare/src/util/folderiterator.cc b/libretroshare/src/util/folderiterator.cc index bf9bfd68b..415aeb085 100644 --- a/libretroshare/src/util/folderiterator.cc +++ b/libretroshare/src/util/folderiterator.cc @@ -44,10 +44,10 @@ FolderIterator::FolderIterator(const std::string& folderName) utf16Name += L"/*.*"; handle = FindFirstFileW(utf16Name.c_str(), &fileInfo); - validity = handle != INVALID_HANDLE_VALUE; + is_open = validity = handle != INVALID_HANDLE_VALUE; #else handle = opendir(folderName.c_str()); - validity = handle != NULL; + is_open = validity = handle != NULL; next(); #endif } @@ -156,6 +156,11 @@ bool FolderIterator::closedir() { validity = false; + if(!is_open) + return true ; + + is_open = false ; + #ifdef WINDOWS_SYS return FindClose(handle) != 0; #else diff --git a/libretroshare/src/util/folderiterator.h b/libretroshare/src/util/folderiterator.h index 1dcc07bc3..21ebacd06 100644 --- a/libretroshare/src/util/folderiterator.h +++ b/libretroshare/src/util/folderiterator.h @@ -50,6 +50,7 @@ public: time_t file_modtime() ; private: + bool is_open; bool validity; #ifdef WINDOWS_SYS