diff options
author | sfan5 <sfan5@live.de> | 2021-09-19 18:16:53 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2021-10-07 00:20:01 +0200 |
commit | 6de8d77e17017cd5cc7b065d42566b6b1cd076cc (patch) | |
tree | 1a6fc291b4df620a4b3c09182b0a69c9b42d2036 /src/filesys.cpp | |
parent | 2b5075f0e2a8223cdb07f000b7e8f874416ed3a8 (diff) | |
download | minetest-6de8d77e17017cd5cc7b065d42566b6b1cd076cc.tar.xz |
Move instead of copy during content install if possible
Diffstat (limited to 'src/filesys.cpp')
-rw-r--r-- | src/filesys.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/filesys.cpp b/src/filesys.cpp index 0972acbf9..44f1c88b3 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -558,6 +558,30 @@ bool CopyDir(const std::string &source, const std::string &target) return false; } +bool MoveDir(const std::string &source, const std::string &target) +{ + infostream << "Moving \"" << source << "\" to \"" << target << "\"" << std::endl; + + // If target exists as empty folder delete, otherwise error + if (fs::PathExists(target)) { + if (rmdir(target.c_str()) != 0) { + errorstream << "MoveDir: target \"" << target + << "\" exists as file or non-empty folder" << std::endl; + return false; + } + } + + // Try renaming first which is instant + if (fs::Rename(source, target)) + return true; + + infostream << "MoveDir: rename not possible, will copy instead" << std::endl; + bool retval = fs::CopyDir(source, target); + if (retval) + retval &= fs::RecursiveDelete(source); + return retval; +} + bool PathStartsWith(const std::string &path, const std::string &prefix) { size_t pathsize = path.size(); |