diff options
| author | 2018-11-30 14:44:13 -0500 | |
|---|---|---|
| committer | 2018-11-30 20:17:28 -0500 | |
| commit | a7d9fe993a3e0e4d939752d2e447cc2b5fdb80f0 (patch) | |
| tree | f5932b1a6b6451c41565b9b5a74dfff4f44fb6f0 /src/core/hle | |
| parent | Merge pull request #1829 from lioncash/lang (diff) | |
| download | yuzu-a7d9fe993a3e0e4d939752d2e447cc2b5fdb80f0.tar.gz yuzu-a7d9fe993a3e0e4d939752d2e447cc2b5fdb80f0.tar.xz yuzu-a7d9fe993a3e0e4d939752d2e447cc2b5fdb80f0.zip | |
service/fsp_srv: Implement CleanDirectoryRecursively
This is the same behavior-wise as DeleteDirectoryRecursively, with the
only difference being that it doesn't delete the top level directory in
the hierarchy, so given:
root_dir/
- some_dir/
- File.txt
- OtherFile.txt
The end result is just:
root_dir/
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.h | 12 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 12 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 2aa77f68d..3bdff4036 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -113,6 +113,18 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str | |||
| 113 | return RESULT_SUCCESS; | 113 | return RESULT_SUCCESS; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | ResultCode VfsDirectoryServiceWrapper::CleanDirectoryRecursively(const std::string& path) const { | ||
| 117 | const std::string sanitized_path(FileUtil::SanitizePath(path)); | ||
| 118 | auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(sanitized_path)); | ||
| 119 | |||
| 120 | if (!dir->CleanSubdirectoryRecursive(FileUtil::GetFilename(sanitized_path))) { | ||
| 121 | // TODO(DarkLordZach): Find a better error code for this | ||
| 122 | return ResultCode(-1); | ||
| 123 | } | ||
| 124 | |||
| 125 | return RESULT_SUCCESS; | ||
| 126 | } | ||
| 127 | |||
| 116 | ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_, | 128 | ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_, |
| 117 | const std::string& dest_path_) const { | 129 | const std::string& dest_path_) const { |
| 118 | std::string src_path(FileUtil::SanitizePath(src_path_)); | 130 | std::string src_path(FileUtil::SanitizePath(src_path_)); |
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 0a6cb6635..278cf90ab 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h | |||
| @@ -114,6 +114,18 @@ public: | |||
| 114 | ResultCode DeleteDirectoryRecursively(const std::string& path) const; | 114 | ResultCode DeleteDirectoryRecursively(const std::string& path) const; |
| 115 | 115 | ||
| 116 | /** | 116 | /** |
| 117 | * Cleans the specified directory. This is similar to DeleteDirectoryRecursively, | ||
| 118 | * in that it deletes all the contents of the specified directory, however, this | ||
| 119 | * function does *not* delete the directory itself. It only deletes everything | ||
| 120 | * within it. | ||
| 121 | * | ||
| 122 | * @param path Path relative to the archive. | ||
| 123 | * | ||
| 124 | * @return Result of the operation. | ||
| 125 | */ | ||
| 126 | ResultCode CleanDirectoryRecursively(const std::string& path) const; | ||
| 127 | |||
| 128 | /** | ||
| 117 | * Rename a File specified by its path | 129 | * Rename a File specified by its path |
| 118 | * @param src_path Source path relative to the archive | 130 | * @param src_path Source path relative to the archive |
| 119 | * @param dest_path Destination path relative to the archive | 131 | * @param dest_path Destination path relative to the archive |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 99d9ebc39..694ec40ec 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -291,7 +291,7 @@ public: | |||
| 291 | {10, &IFileSystem::Commit, "Commit"}, | 291 | {10, &IFileSystem::Commit, "Commit"}, |
| 292 | {11, nullptr, "GetFreeSpaceSize"}, | 292 | {11, nullptr, "GetFreeSpaceSize"}, |
| 293 | {12, nullptr, "GetTotalSpaceSize"}, | 293 | {12, nullptr, "GetTotalSpaceSize"}, |
| 294 | {13, nullptr, "CleanDirectoryRecursively"}, | 294 | {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, |
| 295 | {14, nullptr, "GetFileTimeStampRaw"}, | 295 | {14, nullptr, "GetFileTimeStampRaw"}, |
| 296 | {15, nullptr, "QueryEntry"}, | 296 | {15, nullptr, "QueryEntry"}, |
| 297 | }; | 297 | }; |
| @@ -361,6 +361,16 @@ public: | |||
| 361 | rb.Push(backend.DeleteDirectoryRecursively(name)); | 361 | rb.Push(backend.DeleteDirectoryRecursively(name)); |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | void CleanDirectoryRecursively(Kernel::HLERequestContext& ctx) { | ||
| 365 | const auto file_buffer = ctx.ReadBuffer(); | ||
| 366 | const std::string name = Common::StringFromBuffer(file_buffer); | ||
| 367 | |||
| 368 | LOG_DEBUG(Service_FS, "called. Directory: {}", name); | ||
| 369 | |||
| 370 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 371 | rb.Push(backend.CleanDirectoryRecursively(name)); | ||
| 372 | } | ||
| 373 | |||
| 364 | void RenameFile(Kernel::HLERequestContext& ctx) { | 374 | void RenameFile(Kernel::HLERequestContext& ctx) { |
| 365 | IPC::RequestParser rp{ctx}; | 375 | IPC::RequestParser rp{ctx}; |
| 366 | 376 | ||