From c434eefe94c73978605cf4dfe1459d2f8ede0858 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 3 Dec 2020 13:07:17 -0800 Subject: Change File::DeleteDir return value Makes File::DeleteDir return true when attempting to delete a nonexistent path. The purpose of DeleteDir is to ensure the path doesn't exist after the call, which is better reflected by the new return value. Additionally, none of the current callers actually check the return value so this won't break any existing code. --- Source/Core/Common/FileUtil.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 5e8868da21..6039a449fa 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -257,6 +257,13 @@ bool DeleteDir(const std::string& filename) { INFO_LOG_FMT(COMMON, "DeleteDir: directory {}", filename); + // Return true because we care about the directory not being there, not the actual delete. + if (!File::Exists(filename)) + { + WARN_LOG_FMT(COMMON, "DeleteDir: {} does not exist", filename); + return true; + } + // check if a directory if (!IsDirectory(filename)) { -- cgit v1.2.3 From 4a55511e18c7bb912d882684d591d110576deb47 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 3 Dec 2020 13:13:16 -0800 Subject: Add warning flags to File deletion functions Adds a flag to File::Delete and File::DeleteDir functions to control whether a console warning is emitted when the file or directory doesn't exist. The flag is optional and true by default to match current behavior. --- Source/Core/Common/FileUtil.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Source/Core/Common/FileUtil.cpp') diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index 6039a449fa..0d41395209 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -135,7 +135,7 @@ bool IsFile(const std::string& path) // Deletes a given filename, return true on success // Doesn't supports deleting a directory -bool Delete(const std::string& filename) +bool Delete(const std::string& filename, IfAbsentBehavior behavior) { INFO_LOG_FMT(COMMON, "Delete: file {}", filename); @@ -154,7 +154,10 @@ bool Delete(const std::string& filename) // Return true because we care about the file not being there, not the actual delete. if (!file_info.Exists()) { - WARN_LOG_FMT(COMMON, "Delete: {} does not exist", filename); + if (behavior == IfAbsentBehavior::ConsoleWarning) + { + WARN_LOG_FMT(COMMON, "Delete: {} does not exist", filename); + } return true; } @@ -253,14 +256,17 @@ bool CreateFullPath(const std::string& fullPath) } // Deletes a directory filename, returns true on success -bool DeleteDir(const std::string& filename) +bool DeleteDir(const std::string& filename, IfAbsentBehavior behavior) { INFO_LOG_FMT(COMMON, "DeleteDir: directory {}", filename); // Return true because we care about the directory not being there, not the actual delete. if (!File::Exists(filename)) { - WARN_LOG_FMT(COMMON, "DeleteDir: {} does not exist", filename); + if (behavior == IfAbsentBehavior::ConsoleWarning) + { + WARN_LOG_FMT(COMMON, "DeleteDir: {} does not exist", filename); + } return true; } -- cgit v1.2.3