fs: implement DeleteDirectoryRecursively
This commit is contained in:
parent
4b14e17b18
commit
96b0e9476b
@ -111,6 +111,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool DeleteDirectory(const Path& path) const = 0;
|
virtual bool DeleteDirectory(const Path& path) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a directory specified by its path and anything under it
|
||||||
|
* @param path Path relative to the archive
|
||||||
|
* @return Whether the directory could be deleted
|
||||||
|
*/
|
||||||
|
virtual bool DeleteDirectoryRecursively(const Path& path) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a file specified by its path
|
* Create a file specified by its path
|
||||||
* @param path Path relative to the Archive
|
* @param path Path relative to the Archive
|
||||||
|
@ -51,6 +51,10 @@ bool DiskArchive::DeleteDirectory(const Path& path) const {
|
|||||||
return FileUtil::DeleteDir(mount_point + path.AsString());
|
return FileUtil::DeleteDir(mount_point + path.AsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DiskArchive::DeleteDirectoryRecursively(const Path& path) const {
|
||||||
|
return FileUtil::DeleteDirRecursively(mount_point + path.AsString());
|
||||||
|
}
|
||||||
|
|
||||||
ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
|
||||||
std::string full_path = mount_point + path.AsString();
|
std::string full_path = mount_point + path.AsString();
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
ResultCode DeleteFile(const Path& path) const override;
|
ResultCode DeleteFile(const Path& path) const override;
|
||||||
bool RenameFile(const Path& src_path, const Path& dest_path) const override;
|
bool RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||||
bool DeleteDirectory(const Path& path) const override;
|
bool DeleteDirectory(const Path& path) const override;
|
||||||
|
bool DeleteDirectoryRecursively(const Path& path) const override;
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override;
|
ResultCode CreateFile(const Path& path, u64 size) const override;
|
||||||
bool CreateDirectory(const Path& path) const override;
|
bool CreateDirectory(const Path& path) const override;
|
||||||
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
|
@ -43,6 +43,12 @@ bool IVFCArchive::DeleteDirectory(const Path& path) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
|
||||||
|
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
|
||||||
|
GetName().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
|
ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
|
||||||
LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).",
|
LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).",
|
||||||
GetName().c_str());
|
GetName().c_str());
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
ResultCode DeleteFile(const Path& path) const override;
|
ResultCode DeleteFile(const Path& path) const override;
|
||||||
bool RenameFile(const Path& src_path, const Path& dest_path) const override;
|
bool RenameFile(const Path& src_path, const Path& dest_path) const override;
|
||||||
bool DeleteDirectory(const Path& path) const override;
|
bool DeleteDirectory(const Path& path) const override;
|
||||||
|
bool DeleteDirectoryRecursively(const Path& path) const override;
|
||||||
ResultCode CreateFile(const Path& path, u64 size) const override;
|
ResultCode CreateFile(const Path& path, u64 size) const override;
|
||||||
bool CreateDirectory(const Path& path) const override;
|
bool CreateDirectory(const Path& path) const override;
|
||||||
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
|
||||||
|
@ -362,6 +362,18 @@ ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSy
|
|||||||
ErrorSummary::Canceled, ErrorLevel::Status);
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResultCode DeleteDirectoryRecursivelyFromArchive(ArchiveHandle archive_handle,
|
||||||
|
const FileSys::Path& path) {
|
||||||
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
|
if (archive == nullptr)
|
||||||
|
return ERR_INVALID_ARCHIVE_HANDLE;
|
||||||
|
|
||||||
|
if (archive->DeleteDirectoryRecursively(path))
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
|
}
|
||||||
|
|
||||||
ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
|
ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path,
|
||||||
u64 file_size) {
|
u64 file_size) {
|
||||||
ArchiveBackend* archive = GetArchive(archive_handle);
|
ArchiveBackend* archive = GetArchive(archive_handle);
|
||||||
|
@ -132,6 +132,15 @@ ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle,
|
|||||||
*/
|
*/
|
||||||
ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
|
ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a Directory and anything under it from an Archive
|
||||||
|
* @param archive_handle Handle to an open Archive object
|
||||||
|
* @param path Path to the Directory inside of the Archive
|
||||||
|
* @return Whether deletion succeeded
|
||||||
|
*/
|
||||||
|
ResultCode DeleteDirectoryRecursivelyFromArchive(ArchiveHandle archive_handle,
|
||||||
|
const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a File in an Archive
|
* Create a File in an Archive
|
||||||
* @param archive_handle Handle to an open Archive object
|
* @param archive_handle Handle to an open Archive object
|
||||||
|
@ -234,6 +234,35 @@ static void DeleteDirectory(Service::Interface* self) {
|
|||||||
cmd_buff[1] = DeleteDirectoryFromArchive(archive_handle, dir_path).raw;
|
cmd_buff[1] = DeleteDirectoryFromArchive(archive_handle, dir_path).raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FS_User::DeleteDirectoryRecursively service function
|
||||||
|
* Inputs:
|
||||||
|
* 0 : Command header 0x08070142
|
||||||
|
* 1 : Transaction
|
||||||
|
* 2 : Archive handle lower word
|
||||||
|
* 3 : Archive handle upper word
|
||||||
|
* 4 : Directory path string type
|
||||||
|
* 5 : Directory path string size
|
||||||
|
* 7 : Directory path string data
|
||||||
|
* Outputs:
|
||||||
|
* 1 : Result of function, 0 on success, otherwise error code
|
||||||
|
*/
|
||||||
|
static void DeleteDirectoryRecursively(Service::Interface* self) {
|
||||||
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||||
|
|
||||||
|
ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]);
|
||||||
|
auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
|
||||||
|
u32 dirname_size = cmd_buff[5];
|
||||||
|
u32 dirname_ptr = cmd_buff[7];
|
||||||
|
|
||||||
|
FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
|
||||||
|
|
||||||
|
LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size,
|
||||||
|
dir_path.DebugStr().c_str());
|
||||||
|
|
||||||
|
cmd_buff[1] = DeleteDirectoryRecursivelyFromArchive(archive_handle, dir_path).raw;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FS_User::CreateFile service function
|
* FS_User::CreateFile service function
|
||||||
* Inputs:
|
* Inputs:
|
||||||
@ -868,7 +897,7 @@ const Interface::FunctionInfo FunctionTable[] = {
|
|||||||
{0x08040142, DeleteFile, "DeleteFile"},
|
{0x08040142, DeleteFile, "DeleteFile"},
|
||||||
{0x08050244, RenameFile, "RenameFile"},
|
{0x08050244, RenameFile, "RenameFile"},
|
||||||
{0x08060142, DeleteDirectory, "DeleteDirectory"},
|
{0x08060142, DeleteDirectory, "DeleteDirectory"},
|
||||||
{0x08070142, nullptr, "DeleteDirectoryRecursively"},
|
{0x08070142, DeleteDirectoryRecursively, "DeleteDirectoryRecursively"},
|
||||||
{0x08080202, CreateFile, "CreateFile"},
|
{0x08080202, CreateFile, "CreateFile"},
|
||||||
{0x08090182, CreateDirectory, "CreateDirectory"},
|
{0x08090182, CreateDirectory, "CreateDirectory"},
|
||||||
{0x080A0244, RenameDirectory, "RenameDirectory"},
|
{0x080A0244, RenameDirectory, "RenameDirectory"},
|
||||||
|
Loading…
Reference in New Issue
Block a user