Implement VFS file deletion

This commit is contained in:
Billy Laws 2022-11-10 21:53:17 +00:00
parent 6c968e0357
commit 2ce2604421
5 changed files with 29 additions and 1 deletions

View File

@ -53,6 +53,13 @@ namespace skyline::service::fssrv {
return {}; return {};
} }
Result IFileSystem::DeleteFile(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
std::string path(request.inputBuf.at(0).as_string(true));
backing->DeleteFile(path);
return {};
}
Result IFileSystem::OpenDirectory(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { Result IFileSystem::OpenDirectory(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
std::string path(request.inputBuf.at(0).as_string(true)); std::string path(request.inputBuf.at(0).as_string(true));

View File

@ -23,6 +23,11 @@ namespace skyline::service::fssrv {
*/ */
Result CreateFile(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); Result CreateFile(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/**
* @brief Deletes a file at the specified path in the filesystem
*/
Result DeleteFile(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response);
/** /**
* @brief Creates a directory at the specified path in the filesystem * @brief Creates a directory at the specified path in the filesystem
*/ */
@ -53,6 +58,7 @@ namespace skyline::service::fssrv {
SERVICE_DECL( SERVICE_DECL(
SFUNC(0x0, IFileSystem, CreateFile), SFUNC(0x0, IFileSystem, CreateFile),
SFUNC(0x1, IFileSystem, DeleteFile),
SFUNC(0x2, IFileSystem, CreateDirectory), SFUNC(0x2, IFileSystem, CreateDirectory),
SFUNC(0x7, IFileSystem, GetEntryType), SFUNC(0x7, IFileSystem, GetEntryType),
SFUNC(0x8, IFileSystem, OpenFile), SFUNC(0x8, IFileSystem, OpenFile),

View File

@ -16,6 +16,10 @@ namespace skyline::vfs {
throw exception("This filesystem does not support creating files"); throw exception("This filesystem does not support creating files");
}; };
virtual void DeleteFileImpl(const std::string &path) {
throw exception("This filesystem does not support deleting files");
}
virtual bool CreateDirectoryImpl(const std::string &path, bool parents) { virtual bool CreateDirectoryImpl(const std::string &path, bool parents) {
throw exception("This filesystem does not support creating directories"); throw exception("This filesystem does not support creating directories");
}; };
@ -46,7 +50,11 @@ namespace skyline::vfs {
*/ */
bool CreateFile(const std::string &path, size_t size) { bool CreateFile(const std::string &path, size_t size) {
return CreateFileImpl(path, size); return CreateFileImpl(path, size);
}; }
void DeleteFile(const std::string &path) {
DeleteFileImpl(path);
}
/** /**
* @brief Creates a directory in the filesystem * @brief Creates a directory in the filesystem

View File

@ -38,6 +38,11 @@ namespace skyline::vfs {
return true; return true;
} }
void OsFileSystem::DeleteFileImpl(const std::string &path) {
auto fullPath{basePath + path};
remove(fullPath.c_str());
}
bool OsFileSystem::CreateDirectoryImpl(const std::string &path, bool parents) { bool OsFileSystem::CreateDirectoryImpl(const std::string &path, bool parents) {
auto fullPath{basePath + path + "/"}; auto fullPath{basePath + path + "/"};

View File

@ -16,6 +16,8 @@ namespace skyline::vfs {
protected: protected:
bool CreateFileImpl(const std::string &path, size_t size) override; bool CreateFileImpl(const std::string &path, size_t size) override;
void DeleteFileImpl(const std::string &path) override;
bool CreateDirectoryImpl(const std::string &path, bool parents) override; bool CreateDirectoryImpl(const std::string &path, bool parents) override;
std::shared_ptr<Backing> OpenFileImpl(const std::string &path, Backing::Mode mode) override; std::shared_ptr<Backing> OpenFileImpl(const std::string &path, Backing::Mode mode) override;