diff options
| author | 2018-04-24 10:56:05 +0300 | |
|---|---|---|
| committer | 2018-04-24 10:56:05 +0300 | |
| commit | a0179e5ca5bc54491f03ff60d2f971197eb03e88 (patch) | |
| tree | 99ba0561c6fe429169a40e76a70db7b3f99a71ee /src | |
| parent | Merge pull request #379 from Subv/multi_buffers (diff) | |
| download | yuzu-a0179e5ca5bc54491f03ff60d2f971197eb03e88.tar.gz yuzu-a0179e5ca5bc54491f03ff60d2f971197eb03e88.tar.xz yuzu-a0179e5ca5bc54491f03ff60d2f971197eb03e88.zip | |
Service/FS: implement IFileSystem::RenameFile
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/disk_filesystem.cpp | 12 | ||||
| -rw-r--r-- | src/core/file_sys/disk_filesystem.h | 2 | ||||
| -rw-r--r-- | src/core/file_sys/filesystem.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_filesystem.cpp | 3 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_filesystem.h | 2 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 22 |
6 files changed, 36 insertions, 8 deletions
diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index ca1323873..4d00249fa 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp | |||
| @@ -67,10 +67,16 @@ ResultCode Disk_FileSystem::DeleteFile(const std::string& path) const { | |||
| 67 | return RESULT_SUCCESS; | 67 | return RESULT_SUCCESS; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | ResultCode Disk_FileSystem::RenameFile(const Path& src_path, const Path& dest_path) const { | 70 | ResultCode Disk_FileSystem::RenameFile(const std::string& src_path, |
| 71 | LOG_WARNING(Service_FS, "(STUBBED) called"); | 71 | const std::string& dest_path) const { |
| 72 | const std::string full_src_path = base_directory + src_path; | ||
| 73 | const std::string full_dest_path = base_directory + dest_path; | ||
| 74 | |||
| 75 | if (!FileUtil::Exists(full_src_path)) { | ||
| 76 | return ERROR_PATH_NOT_FOUND; | ||
| 77 | } | ||
| 72 | // TODO(wwylele): Use correct error code | 78 | // TODO(wwylele): Use correct error code |
| 73 | return ResultCode(-1); | 79 | return FileUtil::Rename(full_src_path, full_dest_path) ? RESULT_SUCCESS : ResultCode(-1); |
| 74 | } | 80 | } |
| 75 | 81 | ||
| 76 | ResultCode Disk_FileSystem::DeleteDirectory(const Path& path) const { | 82 | ResultCode Disk_FileSystem::DeleteDirectory(const Path& path) const { |
diff --git a/src/core/file_sys/disk_filesystem.h b/src/core/file_sys/disk_filesystem.h index 8f9e1145a..591e39fda 100644 --- a/src/core/file_sys/disk_filesystem.h +++ b/src/core/file_sys/disk_filesystem.h | |||
| @@ -26,7 +26,7 @@ public: | |||
| 26 | ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path, | 26 | ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path, |
| 27 | Mode mode) const override; | 27 | Mode mode) const override; |
| 28 | ResultCode DeleteFile(const std::string& path) const override; | 28 | ResultCode DeleteFile(const std::string& path) const override; |
| 29 | ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; | 29 | ResultCode RenameFile(const std::string& src_path, const std::string& dest_path) const override; |
| 30 | ResultCode DeleteDirectory(const Path& path) const override; | 30 | ResultCode DeleteDirectory(const Path& path) const override; |
| 31 | ResultCode DeleteDirectoryRecursively(const Path& path) const override; | 31 | ResultCode DeleteDirectoryRecursively(const Path& path) const override; |
| 32 | ResultCode CreateFile(const std::string& path, u64 size) const override; | 32 | ResultCode CreateFile(const std::string& path, u64 size) const override; |
diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h index beefcfdb2..295a3133e 100644 --- a/src/core/file_sys/filesystem.h +++ b/src/core/file_sys/filesystem.h | |||
| @@ -126,7 +126,8 @@ public: | |||
| 126 | * @param dest_path Destination path relative to the archive | 126 | * @param dest_path Destination path relative to the archive |
| 127 | * @return Result of the operation | 127 | * @return Result of the operation |
| 128 | */ | 128 | */ |
| 129 | virtual ResultCode RenameFile(const Path& src_path, const Path& dest_path) const = 0; | 129 | virtual ResultCode RenameFile(const std::string& src_path, |
| 130 | const std::string& dest_path) const = 0; | ||
| 130 | 131 | ||
| 131 | /** | 132 | /** |
| 132 | * Rename a Directory specified by its path | 133 | * Rename a Directory specified by its path |
diff --git a/src/core/file_sys/romfs_filesystem.cpp b/src/core/file_sys/romfs_filesystem.cpp index 3d77e2d5f..b9982e6fa 100644 --- a/src/core/file_sys/romfs_filesystem.cpp +++ b/src/core/file_sys/romfs_filesystem.cpp | |||
| @@ -27,7 +27,8 @@ ResultCode RomFS_FileSystem::DeleteFile(const std::string& path) const { | |||
| 27 | return ResultCode(-1); | 27 | return ResultCode(-1); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | ResultCode RomFS_FileSystem::RenameFile(const Path& src_path, const Path& dest_path) const { | 30 | ResultCode RomFS_FileSystem::RenameFile(const std::string& src_path, |
| 31 | const std::string& dest_path) const { | ||
| 31 | LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).", | 32 | LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).", |
| 32 | GetName().c_str()); | 33 | GetName().c_str()); |
| 33 | // TODO(wwylele): Use correct error code | 34 | // TODO(wwylele): Use correct error code |
diff --git a/src/core/file_sys/romfs_filesystem.h b/src/core/file_sys/romfs_filesystem.h index 1b5cac409..ba9d85823 100644 --- a/src/core/file_sys/romfs_filesystem.h +++ b/src/core/file_sys/romfs_filesystem.h | |||
| @@ -32,7 +32,7 @@ public: | |||
| 32 | ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path, | 32 | ResultVal<std::unique_ptr<StorageBackend>> OpenFile(const std::string& path, |
| 33 | Mode mode) const override; | 33 | Mode mode) const override; |
| 34 | ResultCode DeleteFile(const std::string& path) const override; | 34 | ResultCode DeleteFile(const std::string& path) const override; |
| 35 | ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; | 35 | ResultCode RenameFile(const std::string& src_path, const std::string& dest_path) const override; |
| 36 | ResultCode DeleteDirectory(const Path& path) const override; | 36 | ResultCode DeleteDirectory(const Path& path) const override; |
| 37 | ResultCode DeleteDirectoryRecursively(const Path& path) const override; | 37 | ResultCode DeleteDirectoryRecursively(const Path& path) const override; |
| 38 | ResultCode CreateFile(const std::string& path, u64 size) const override; | 38 | ResultCode CreateFile(const std::string& path, u64 size) const override; |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 2f476c869..02e270f26 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -239,7 +239,7 @@ public: | |||
| 239 | {2, &IFileSystem::CreateDirectory, "CreateDirectory"}, | 239 | {2, &IFileSystem::CreateDirectory, "CreateDirectory"}, |
| 240 | {3, nullptr, "DeleteDirectory"}, | 240 | {3, nullptr, "DeleteDirectory"}, |
| 241 | {4, nullptr, "DeleteDirectoryRecursively"}, | 241 | {4, nullptr, "DeleteDirectoryRecursively"}, |
| 242 | {5, nullptr, "RenameFile"}, | 242 | {5, &IFileSystem::RenameFile, "RenameFile"}, |
| 243 | {6, nullptr, "RenameDirectory"}, | 243 | {6, nullptr, "RenameDirectory"}, |
| 244 | {7, &IFileSystem::GetEntryType, "GetEntryType"}, | 244 | {7, &IFileSystem::GetEntryType, "GetEntryType"}, |
| 245 | {8, &IFileSystem::OpenFile, "OpenFile"}, | 245 | {8, &IFileSystem::OpenFile, "OpenFile"}, |
| @@ -300,6 +300,26 @@ public: | |||
| 300 | rb.Push(backend->CreateDirectory(name)); | 300 | rb.Push(backend->CreateDirectory(name)); |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | void RenameFile(Kernel::HLERequestContext& ctx) { | ||
| 304 | IPC::RequestParser rp{ctx}; | ||
| 305 | |||
| 306 | std::vector<u8> buffer; | ||
| 307 | buffer.resize(ctx.BufferDescriptorX()[0].Size()); | ||
| 308 | Memory::ReadBlock(ctx.BufferDescriptorX()[0].Address(), buffer.data(), buffer.size()); | ||
| 309 | auto end = std::find(buffer.begin(), buffer.end(), '\0'); | ||
| 310 | std::string src_name(buffer.begin(), end); | ||
| 311 | |||
| 312 | buffer.resize(ctx.BufferDescriptorX()[1].Size()); | ||
| 313 | Memory::ReadBlock(ctx.BufferDescriptorX()[1].Address(), buffer.data(), buffer.size()); | ||
| 314 | end = std::find(buffer.begin(), buffer.end(), '\0'); | ||
| 315 | std::string dst_name(buffer.begin(), end); | ||
| 316 | |||
| 317 | LOG_DEBUG(Service_FS, "called file '%s' to file '%s'", src_name.c_str(), dst_name.c_str()); | ||
| 318 | |||
| 319 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 320 | rb.Push(backend->RenameFile(src_name, dst_name)); | ||
| 321 | } | ||
| 322 | |||
| 303 | void OpenFile(Kernel::HLERequestContext& ctx) { | 323 | void OpenFile(Kernel::HLERequestContext& ctx) { |
| 304 | IPC::RequestParser rp{ctx}; | 324 | IPC::RequestParser rp{ctx}; |
| 305 | 325 | ||