diff options
| author | Stefan Boberg <[email protected]> | 2024-10-03 12:27:32 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-10-03 12:27:32 +0200 |
| commit | ba487f5ee415a39453de2800e1bc17aef962b7dc (patch) | |
| tree | 3a8b3fa29296778e98c7b89abf57c7eef235c1f4 /src/zencore/filesystem.cpp | |
| parent | 5.5.8 (diff) | |
| download | zen-ba487f5ee415a39453de2800e1bc17aef962b7dc.tar.xz zen-ba487f5ee415a39453de2800e1bc17aef962b7dc.zip | |
simplified CleanDirectory implementation (#182)
we use the std implementation for all normal cases now. The Windows-only path still exists for VFS cleanup
Diffstat (limited to 'src/zencore/filesystem.cpp')
| -rw-r--r-- | src/zencore/filesystem.cpp | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index d79a39880..7ca076daa 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -93,6 +93,8 @@ CreateDirectories(const wchar_t* Dir) // Erase all files and directories in a given directory, leaving an empty directory // behind +bool DeleteDirectoriesInternal(const wchar_t* DirPath); + static bool WipeDirectory(const wchar_t* DirPath, bool KeepDotFiles) { @@ -159,7 +161,7 @@ WipeDirectory(const wchar_t* DirPath, bool KeepDotFiles) } } - bool Succeeded = DeleteDirectories(Path.c_str()); + bool Succeeded = DeleteDirectoriesInternal(Path.c_str()); if (!Succeeded) { @@ -193,26 +195,13 @@ WipeDirectory(const wchar_t* DirPath, bool KeepDotFiles) } bool -DeleteDirectories(const wchar_t* DirPath) +DeleteDirectoriesInternal(const wchar_t* DirPath) { const bool KeepDotFiles = false; return WipeDirectory(DirPath, KeepDotFiles) && RemoveDirectoryW(DirPath) == TRUE; } bool -CleanDirectory(const wchar_t* DirPath) -{ - if (std::filesystem::exists(DirPath)) - { - const bool KeepDotFiles = false; - - return WipeDirectory(DirPath, KeepDotFiles); - } - - return CreateDirectories(DirPath); -} - -bool CleanDirectory(const wchar_t* DirPath, bool KeepDotFiles) { if (std::filesystem::exists(DirPath)) @@ -222,7 +211,6 @@ CleanDirectory(const wchar_t* DirPath, bool KeepDotFiles) return CreateDirectories(DirPath); } - #endif // ZEN_PLATFORM_WINDOWS bool @@ -252,35 +240,29 @@ CreateDirectories(const std::filesystem::path& Dir) bool DeleteDirectories(const std::filesystem::path& Dir) { -#if ZEN_PLATFORM_WINDOWS - return DeleteDirectories(Dir.c_str()); -#else std::error_code ErrorCode; return std::filesystem::remove_all(Dir, ErrorCode); -#endif } bool CleanDirectory(const std::filesystem::path& Dir) { -#if ZEN_PLATFORM_WINDOWS - return CleanDirectory(Dir.c_str()); -#else if (std::filesystem::exists(Dir)) { bool Success = true; - std::error_code ErrorCode; for (const auto& Item : std::filesystem::directory_iterator(Dir)) { - Success &= std::filesystem::remove_all(Item, ErrorCode); + std::error_code ErrorCode; + const uintmax_t RemovedCount = std::filesystem::remove_all(Item, ErrorCode); + + Success = Success && !ErrorCode && RemovedCount; } return Success; } return CreateDirectories(Dir); -#endif } bool |