summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-09-20 14:50:11 +0200
committerGitHub <noreply@github.com>2021-09-20 14:50:11 +0200
commitb43cee8fe4a83b54fda736504942e9c82eae9344 (patch)
tree5e3fb470ca8a569b0ed474383e4a2ee6cd51d287 /Source/Core
parent276ea43237f8675840621932c45b2ba1fb3120df (diff)
parentf76aaf65f6dfc56282347b87d78feca536a105b0 (diff)
Merge pull request #10098 from AdmiralCurtiss/scan-dir-tree-trailing-slash
Common/FileUtil: Strip trailing path separator in ScanDirectoryTree().
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/FileUtil.cpp10
-rw-r--r--Source/Core/Common/FileUtil.h2
2 files changed, 10 insertions, 2 deletions
diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp
index 2204f066e4..1bc92c8d70 100644
--- a/Source/Core/Common/FileUtil.cpp
+++ b/Source/Core/Common/FileUtil.cpp
@@ -483,8 +483,16 @@ bool CreateEmptyFile(const std::string& filename)
}
// Recursive or non-recursive list of files and directories under directory.
-FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive)
+FSTEntry ScanDirectoryTree(std::string directory, bool recursive)
{
+#ifdef _WIN32
+ if (!directory.empty() && (directory.back() == '/' || directory.back() == '\\'))
+ directory.pop_back();
+#else
+ if (!directory.empty() && directory.back() == '/')
+ directory.pop_back();
+#endif
+
INFO_LOG_FMT(COMMON, "ScanDirectoryTree: directory {}", directory);
FSTEntry parent_entry;
parent_entry.physicalName = directory;
diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h
index 1a487bbe4e..e2021bdab4 100644
--- a/Source/Core/Common/FileUtil.h
+++ b/Source/Core/Common/FileUtil.h
@@ -176,7 +176,7 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename);
bool CreateEmptyFile(const std::string& filename);
// Recursive or non-recursive list of files and directories under directory.
-FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive);
+FSTEntry ScanDirectoryTree(std::string directory, bool recursive);
// deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string& directory);