summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2018-05-08 23:55:13 +0200
committerLéo Lam <leo@innovatetechnologi.es>2018-05-08 23:55:13 +0200
commit7feabcd09690dc4ebed4f32389ea31b6025563a2 (patch)
tree88d0a9f50a8672643cc936484dfc049f3b49b66d /Source/Core
parent10d230a512b99aee66f7343481ed13d83557de22 (diff)
IOS/FS: Fix rename not handling existing target correctly
The existing backend did not handle cases where the target exists correctly. This is a bug that has been around forever but was only recently exposed when ES started to use our FS code. Also adds some unit tests to make sure this won't get broken again.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/IOS/FS/HostBackend/FS.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp
index 112eee0e66..19479bf318 100644
--- a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp
+++ b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp
@@ -232,10 +232,17 @@ ResultCode HostFileSystem::Rename(Uid, Gid, const std::string& old_path,
// try to make the basis directory
File::CreateFullPath(new_name);
- // if there is already a file, delete it
- if (File::Exists(old_name) && File::Exists(new_name))
+ // If there is already something of the same type at the new path, delete it.
+ if (File::Exists(new_name))
{
- File::Delete(new_name);
+ const bool old_is_file = File::IsFile(old_name);
+ const bool new_is_file = File::IsFile(new_name);
+ if (old_is_file && new_is_file)
+ File::Delete(new_name);
+ else if (!old_is_file && !new_is_file)
+ File::DeleteDirRecursively(new_name);
+ else
+ return ResultCode::Invalid;
}
// finally try to rename the file