summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp30
1 files changed, 2 insertions, 28 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 7752c0421..d5f6ea2ee 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -98,11 +98,6 @@ bool Delete(const fs::path& path) {
98bool CreateDir(const fs::path& path) { 98bool CreateDir(const fs::path& path) {
99 LOG_TRACE(Common_Filesystem, "directory {}", path.string()); 99 LOG_TRACE(Common_Filesystem, "directory {}", path.string());
100 100
101 if (Exists(path)) {
102 LOG_DEBUG(Common_Filesystem, "path exists {}", path.string());
103 return true;
104 }
105
106 std::error_code ec; 101 std::error_code ec;
107 const bool success = fs::create_directory(path, ec); 102 const bool success = fs::create_directory(path, ec);
108 103
@@ -114,41 +109,20 @@ bool CreateDir(const fs::path& path) {
114 return true; 109 return true;
115} 110}
116 111
117bool CreateDirs(const fs::path& path) { 112bool CreateFullPath(const fs::path& path) {
118 LOG_TRACE(Common_Filesystem, "path {}", path.string()); 113 LOG_TRACE(Common_Filesystem, "path {}", path.string());
119 114
120 if (Exists(path)) {
121 LOG_DEBUG(Common_Filesystem, "path exists {}", path.string());
122 return true;
123 }
124
125 std::error_code ec; 115 std::error_code ec;
126 const bool success = fs::create_directories(path, ec); 116 const bool success = fs::create_directories(path, ec);
127 117
128 if (!success) { 118 if (!success) {
129 LOG_ERROR(Common_Filesystem, "Unable to create directories: {}", ec.message()); 119 LOG_ERROR(Common_Filesystem, "Unable to create full path: {}", ec.message());
130 return false; 120 return false;
131 } 121 }
132 122
133 return true; 123 return true;
134} 124}
135 125
136bool CreateFullPath(const fs::path& path) {
137 LOG_TRACE(Common_Filesystem, "path {}", path);
138
139 // Removes trailing slashes and turns any '\' into '/'
140 const auto new_path = SanitizePath(path.string(), DirectorySeparator::ForwardSlash);
141
142 if (new_path.rfind('.') == std::string::npos) {
143 // The path is a directory
144 return CreateDirs(new_path);
145 } else {
146 // The path is a file
147 // Creates directory preceding the last '/'
148 return CreateDirs(new_path.substr(0, new_path.rfind('/')));
149 }
150}
151
152bool Rename(const fs::path& src, const fs::path& dst) { 126bool Rename(const fs::path& src, const fs::path& dst) {
153 LOG_TRACE(Common_Filesystem, "{} --> {}", src.string(), dst.string()); 127 LOG_TRACE(Common_Filesystem, "{} --> {}", src.string(), dst.string());
154 128