diff options
| author | 2017-07-31 21:50:48 -0700 | |
|---|---|---|
| committer | 2017-07-31 21:50:48 -0700 | |
| commit | 035716d57bfc2142779e421ee242efc0d51059f6 (patch) | |
| tree | 52f3da0860c429449e42f05ecf3454d2b1ab9435 | |
| parent | Merge pull request #2848 from wwylele/shader-loop-fix (diff) | |
| parent | Handle invalid filenames when renaming files/directories (diff) | |
| download | yuzu-035716d57bfc2142779e421ee242efc0d51059f6.tar.gz yuzu-035716d57bfc2142779e421ee242efc0d51059f6.tar.xz yuzu-035716d57bfc2142779e421ee242efc0d51059f6.zip | |
Merge pull request #2850 from j-selby/fix_invalid_paths
Handle invalid filenames when renaming files/directories
Diffstat (limited to '')
| -rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 41 | ||||
| -rw-r--r-- | src/core/file_sys/savedata_archive.cpp | 41 |
2 files changed, 78 insertions, 4 deletions
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index 679909d06..fe3dce5d4 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp | |||
| @@ -121,7 +121,25 @@ ResultCode SDMCArchive::DeleteFile(const Path& path) const { | |||
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | ResultCode SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | 123 | ResultCode SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { |
| 124 | if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString())) { | 124 | const PathParser path_parser_src(src_path); |
| 125 | |||
| 126 | // TODO: Verify these return codes with HW | ||
| 127 | if (!path_parser_src.IsValid()) { | ||
| 128 | LOG_ERROR(Service_FS, "Invalid src path %s", src_path.DebugStr().c_str()); | ||
| 129 | return ERROR_INVALID_PATH; | ||
| 130 | } | ||
| 131 | |||
| 132 | const PathParser path_parser_dest(dest_path); | ||
| 133 | |||
| 134 | if (!path_parser_dest.IsValid()) { | ||
| 135 | LOG_ERROR(Service_FS, "Invalid dest path %s", dest_path.DebugStr().c_str()); | ||
| 136 | return ERROR_INVALID_PATH; | ||
| 137 | } | ||
| 138 | |||
| 139 | const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||
| 140 | const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||
| 141 | |||
| 142 | if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||
| 125 | return RESULT_SUCCESS; | 143 | return RESULT_SUCCESS; |
| 126 | } | 144 | } |
| 127 | 145 | ||
| @@ -260,8 +278,27 @@ ResultCode SDMCArchive::CreateDirectory(const Path& path) const { | |||
| 260 | } | 278 | } |
| 261 | 279 | ||
| 262 | ResultCode SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | 280 | ResultCode SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { |
| 263 | if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString())) | 281 | const PathParser path_parser_src(src_path); |
| 282 | |||
| 283 | // TODO: Verify these return codes with HW | ||
| 284 | if (!path_parser_src.IsValid()) { | ||
| 285 | LOG_ERROR(Service_FS, "Invalid src path %s", src_path.DebugStr().c_str()); | ||
| 286 | return ERROR_INVALID_PATH; | ||
| 287 | } | ||
| 288 | |||
| 289 | const PathParser path_parser_dest(dest_path); | ||
| 290 | |||
| 291 | if (!path_parser_dest.IsValid()) { | ||
| 292 | LOG_ERROR(Service_FS, "Invalid dest path %s", dest_path.DebugStr().c_str()); | ||
| 293 | return ERROR_INVALID_PATH; | ||
| 294 | } | ||
| 295 | |||
| 296 | const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||
| 297 | const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||
| 298 | |||
| 299 | if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||
| 264 | return RESULT_SUCCESS; | 300 | return RESULT_SUCCESS; |
| 301 | } | ||
| 265 | 302 | ||
| 266 | // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't | 303 | // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't |
| 267 | // exist or similar. Verify. | 304 | // exist or similar. Verify. |
diff --git a/src/core/file_sys/savedata_archive.cpp b/src/core/file_sys/savedata_archive.cpp index f540c4a93..f8f811ba0 100644 --- a/src/core/file_sys/savedata_archive.cpp +++ b/src/core/file_sys/savedata_archive.cpp | |||
| @@ -106,7 +106,25 @@ ResultCode SaveDataArchive::DeleteFile(const Path& path) const { | |||
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | ResultCode SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | 108 | ResultCode SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_path) const { |
| 109 | if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString())) { | 109 | const PathParser path_parser_src(src_path); |
| 110 | |||
| 111 | // TODO: Verify these return codes with HW | ||
| 112 | if (!path_parser_src.IsValid()) { | ||
| 113 | LOG_ERROR(Service_FS, "Invalid src path %s", src_path.DebugStr().c_str()); | ||
| 114 | return ERROR_INVALID_PATH; | ||
| 115 | } | ||
| 116 | |||
| 117 | const PathParser path_parser_dest(dest_path); | ||
| 118 | |||
| 119 | if (!path_parser_dest.IsValid()) { | ||
| 120 | LOG_ERROR(Service_FS, "Invalid dest path %s", dest_path.DebugStr().c_str()); | ||
| 121 | return ERROR_INVALID_PATH; | ||
| 122 | } | ||
| 123 | |||
| 124 | const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||
| 125 | const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||
| 126 | |||
| 127 | if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||
| 110 | return RESULT_SUCCESS; | 128 | return RESULT_SUCCESS; |
| 111 | } | 129 | } |
| 112 | 130 | ||
| @@ -247,8 +265,27 @@ ResultCode SaveDataArchive::CreateDirectory(const Path& path) const { | |||
| 247 | } | 265 | } |
| 248 | 266 | ||
| 249 | ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | 267 | ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { |
| 250 | if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString())) | 268 | const PathParser path_parser_src(src_path); |
| 269 | |||
| 270 | // TODO: Verify these return codes with HW | ||
| 271 | if (!path_parser_src.IsValid()) { | ||
| 272 | LOG_ERROR(Service_FS, "Invalid src path %s", src_path.DebugStr().c_str()); | ||
| 273 | return ERROR_INVALID_PATH; | ||
| 274 | } | ||
| 275 | |||
| 276 | const PathParser path_parser_dest(dest_path); | ||
| 277 | |||
| 278 | if (!path_parser_dest.IsValid()) { | ||
| 279 | LOG_ERROR(Service_FS, "Invalid dest path %s", dest_path.DebugStr().c_str()); | ||
| 280 | return ERROR_INVALID_PATH; | ||
| 281 | } | ||
| 282 | |||
| 283 | const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||
| 284 | const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||
| 285 | |||
| 286 | if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||
| 251 | return RESULT_SUCCESS; | 287 | return RESULT_SUCCESS; |
| 288 | } | ||
| 252 | 289 | ||
| 253 | // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't | 290 | // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't |
| 254 | // exist or similar. Verify. | 291 | // exist or similar. Verify. |