diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-12-09 09:22:16 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-12-09 09:42:03 +0100 |
commit | 532983437616e15539b448594a360c138995e282 (patch) | |
tree | 2537197bb02dfce45dbc55933cabfa06a1b5bc25 /src/common/file_util.cpp | |
parent | common/file_util: Succeed on CreateDir when the directory exists (diff) | |
download | yuzu-532983437616e15539b448594a360c138995e282.tar yuzu-532983437616e15539b448594a360c138995e282.tar.gz yuzu-532983437616e15539b448594a360c138995e282.tar.bz2 yuzu-532983437616e15539b448594a360c138995e282.tar.lz yuzu-532983437616e15539b448594a360c138995e282.tar.xz yuzu-532983437616e15539b448594a360c138995e282.tar.zst yuzu-532983437616e15539b448594a360c138995e282.zip |
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r-- | src/common/file_util.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c4d738bb6..7752c0421 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -114,20 +114,41 @@ bool CreateDir(const fs::path& path) { return true; } -bool CreateFullPath(const fs::path& path) { +bool CreateDirs(const fs::path& path) { LOG_TRACE(Common_Filesystem, "path {}", path.string()); + if (Exists(path)) { + LOG_DEBUG(Common_Filesystem, "path exists {}", path.string()); + return true; + } + std::error_code ec; const bool success = fs::create_directories(path, ec); if (!success) { - LOG_ERROR(Common_Filesystem, "Unable to create full path: {}", ec.message()); + LOG_ERROR(Common_Filesystem, "Unable to create directories: {}", ec.message()); return false; } return true; } +bool CreateFullPath(const fs::path& path) { + LOG_TRACE(Common_Filesystem, "path {}", path); + + // Removes trailing slashes and turns any '\' into '/' + const auto new_path = SanitizePath(path.string(), DirectorySeparator::ForwardSlash); + + if (new_path.rfind('.') == std::string::npos) { + // The path is a directory + return CreateDirs(new_path); + } else { + // The path is a file + // Creates directory preceding the last '/' + return CreateDirs(new_path.substr(0, new_path.rfind('/'))); + } +} + bool Rename(const fs::path& src, const fs::path& dst) { LOG_TRACE(Common_Filesystem, "{} --> {}", src.string(), dst.string()); |