Updated archive.cpp functions for proper error handling
This commit is contained in:
parent
e5ff01c2cd
commit
139a4d91d9
|
@ -43,12 +43,6 @@ bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Rename a File specified by its path
|
|
||||||
* @param src_path Source path relative to the archive
|
|
||||||
* @param dest_path Destination path relative to the archive
|
|
||||||
* @return Whether rename succeeded
|
|
||||||
*/
|
|
||||||
bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
||||||
ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
|
ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -74,12 +68,6 @@ bool Archive_RomFS::CreateDirectory(const Path& path) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Rename a Directory specified by its path
|
|
||||||
* @param src_path Source path relative to the archive
|
|
||||||
* @param dest_path Destination path relative to the archive
|
|
||||||
* @return Whether rename succeeded
|
|
||||||
*/
|
|
||||||
bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
||||||
ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
|
ERROR_LOG(FILESYS, "Attempted to rename a file within ROMFS.");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -66,12 +66,6 @@ bool Archive_SDMC::DeleteFile(const FileSys::Path& path) const {
|
||||||
return FileUtil::Delete(GetMountPoint() + path.AsString());
|
return FileUtil::Delete(GetMountPoint() + path.AsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Rename a File specified by its path
|
|
||||||
* @param src_path Source path relative to the archive
|
|
||||||
* @param dest_path Destination path relative to the archive
|
|
||||||
* @return Whether rename succeeded
|
|
||||||
*/
|
|
||||||
bool Archive_SDMC::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
bool Archive_SDMC::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
||||||
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
|
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
|
||||||
}
|
}
|
||||||
|
@ -94,12 +88,6 @@ bool Archive_SDMC::CreateDirectory(const Path& path) const {
|
||||||
return FileUtil::CreateDir(GetMountPoint() + path.AsString());
|
return FileUtil::CreateDir(GetMountPoint() + path.AsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Rename a Directory specified by its path
|
|
||||||
* @param src_path Source path relative to the archive
|
|
||||||
* @param dest_path Destination path relative to the archive
|
|
||||||
* @return Whether rename succeeded
|
|
||||||
*/
|
|
||||||
bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const {
|
||||||
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
|
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,97 +340,68 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
|
||||||
return MakeResult<Handle>(handle);
|
return MakeResult<Handle>(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ResultCode DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
||||||
* Delete a File from an Archive
|
|
||||||
* @param archive_handle Handle to an open Archive object
|
|
||||||
* @param path Path to the File inside of the Archive
|
|
||||||
* @return Whether deletion succeeded
|
|
||||||
*/
|
|
||||||
Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
|
||||||
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return -1;
|
return InvalidHandle(ErrorModule::FS);
|
||||||
if (archive->backend->DeleteFile(path))
|
if (archive->backend->DeleteFile(path))
|
||||||
return 0;
|
return RESULT_SUCCESS;
|
||||||
return -1;
|
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ResultCode RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
||||||
* Rename a File between two Archives
|
Handle dest_archive_handle, const FileSys::Path& dest_path) {
|
||||||
* @param src_archive_handle Handle to the source Archive object
|
|
||||||
* @param src_path Path to the File inside of the source Archive
|
|
||||||
* @param dest_archive_handle Handle to the destination Archive object
|
|
||||||
* @param dest_path Path to the File inside of the destination Archive
|
|
||||||
* @return Whether rename succeeded
|
|
||||||
*/
|
|
||||||
Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
|
||||||
Handle dest_archive_handle, const FileSys::Path& dest_path) {
|
|
||||||
Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
|
Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
|
||||||
Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
|
Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
|
||||||
if (src_archive == nullptr || dest_archive == nullptr)
|
if (src_archive == nullptr || dest_archive == nullptr)
|
||||||
return -1;
|
return InvalidHandle(ErrorModule::FS);
|
||||||
if (src_archive == dest_archive) {
|
if (src_archive == dest_archive) {
|
||||||
if (src_archive->backend->RenameFile(src_path, dest_path))
|
if (src_archive->backend->RenameFile(src_path, dest_path))
|
||||||
return 0;
|
return RESULT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement renaming across archives
|
// TODO: Implement renaming across archives
|
||||||
return -1;
|
return UnimplementedFunction(ErrorModule::FS);
|
||||||
}
|
}
|
||||||
return -1;
|
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ResultCode DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
||||||
* Delete a Directory 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
|
|
||||||
*/
|
|
||||||
Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
|
||||||
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return -1;
|
return InvalidHandle(ErrorModule::FS);
|
||||||
if (archive->backend->DeleteDirectory(path))
|
if (archive->backend->DeleteDirectory(path))
|
||||||
return 0;
|
return RESULT_SUCCESS;
|
||||||
return -1;
|
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ResultCode CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
||||||
* Create a Directory from an Archive
|
|
||||||
* @param archive_handle Handle to an open Archive object
|
|
||||||
* @param path Path to the Directory inside of the Archive
|
|
||||||
* @return Whether creation succeeded
|
|
||||||
*/
|
|
||||||
Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
|
|
||||||
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
|
||||||
if (archive == nullptr)
|
if (archive == nullptr)
|
||||||
return -1;
|
return InvalidHandle(ErrorModule::FS);
|
||||||
if (archive->backend->CreateDirectory(path))
|
if (archive->backend->CreateDirectory(path))
|
||||||
return 0;
|
return RESULT_SUCCESS;
|
||||||
return -1;
|
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
|
ErrorSummary::Canceled, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
ResultCode RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
||||||
* Rename a Directory between two Archives
|
Handle dest_archive_handle, const FileSys::Path& dest_path) {
|
||||||
* @param src_archive_handle Handle to the source Archive object
|
|
||||||
* @param src_path Path to the Directory inside of the source Archive
|
|
||||||
* @param dest_archive_handle Handle to the destination Archive object
|
|
||||||
* @param dest_path Path to the Directory inside of the destination Archive
|
|
||||||
* @return Whether rename succeeded
|
|
||||||
*/
|
|
||||||
Result RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
|
||||||
Handle dest_archive_handle, const FileSys::Path& dest_path) {
|
|
||||||
Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
|
Archive* src_archive = Kernel::g_object_pool.GetFast<Archive>(src_archive_handle);
|
||||||
Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
|
Archive* dest_archive = Kernel::g_object_pool.GetFast<Archive>(dest_archive_handle);
|
||||||
if (src_archive == nullptr || dest_archive == nullptr)
|
if (src_archive == nullptr || dest_archive == nullptr)
|
||||||
return -1;
|
return InvalidHandle(ErrorModule::FS);
|
||||||
if (src_archive == dest_archive) {
|
if (src_archive == dest_archive) {
|
||||||
if (src_archive->backend->RenameDirectory(src_path, dest_path))
|
if (src_archive->backend->RenameDirectory(src_path, dest_path))
|
||||||
return 0;
|
return RESULT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement renaming across archives
|
// TODO: Implement renaming across archives
|
||||||
return -1;
|
return UnimplementedFunction(ErrorModule::FS);
|
||||||
}
|
}
|
||||||
return -1;
|
return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
|
||||||
|
ErrorSummary::NothingHappened, ErrorLevel::Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,7 +50,7 @@ ResultVal<Handle> OpenFileFromArchive(Handle archive_handle, const FileSys::Path
|
||||||
* @param path Path to the File inside of the Archive
|
* @param path Path to the File inside of the Archive
|
||||||
* @return Whether deletion succeeded
|
* @return Whether deletion succeeded
|
||||||
*/
|
*/
|
||||||
Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
|
ResultCode DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a File between two Archives
|
* Rename a File between two Archives
|
||||||
|
@ -60,8 +60,8 @@ Result DeleteFileFromArchive(Handle archive_handle, const FileSys::Path& path);
|
||||||
* @param dest_path Path to the File inside of the destination Archive
|
* @param dest_path Path to the File inside of the destination Archive
|
||||||
* @return Whether rename succeeded
|
* @return Whether rename succeeded
|
||||||
*/
|
*/
|
||||||
Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
ResultCode RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
||||||
Handle dest_archive_handle, const FileSys::Path& dest_path);
|
Handle dest_archive_handle, const FileSys::Path& dest_path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a Directory from an Archive
|
* Delete a Directory from an Archive
|
||||||
|
@ -69,7 +69,7 @@ Result RenameFileBetweenArchives(Handle src_archive_handle, const FileSys::Path&
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Whether deletion succeeded
|
* @return Whether deletion succeeded
|
||||||
*/
|
*/
|
||||||
Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
|
ResultCode DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Directory from an Archive
|
* Create a Directory from an Archive
|
||||||
|
@ -77,7 +77,7 @@ Result DeleteDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
|
||||||
* @param path Path to the Directory inside of the Archive
|
* @param path Path to the Directory inside of the Archive
|
||||||
* @return Whether creation of directory succeeded
|
* @return Whether creation of directory succeeded
|
||||||
*/
|
*/
|
||||||
Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
|
ResultCode CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename a Directory between two Archives
|
* Rename a Directory between two Archives
|
||||||
|
@ -87,8 +87,8 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& pa
|
||||||
* @param dest_path Path to the Directory inside of the destination Archive
|
* @param dest_path Path to the Directory inside of the destination Archive
|
||||||
* @return Whether rename succeeded
|
* @return Whether rename succeeded
|
||||||
*/
|
*/
|
||||||
Result RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
ResultCode RenameDirectoryBetweenArchives(Handle src_archive_handle, const FileSys::Path& src_path,
|
||||||
Handle dest_archive_handle, const FileSys::Path& dest_path);
|
Handle dest_archive_handle, const FileSys::Path& dest_path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a Directory from an Archive
|
* Open a Directory from an Archive
|
||||||
|
|
|
@ -159,7 +159,7 @@ void DeleteFile(Service::Interface* self) {
|
||||||
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
|
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
|
||||||
filename_type, filename_size, file_path.DebugStr().c_str());
|
filename_type, filename_size, file_path.DebugStr().c_str());
|
||||||
|
|
||||||
cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path);
|
cmd_buff[1] = Kernel::DeleteFileFromArchive(archive_handle, file_path).raw;
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "called");
|
DEBUG_LOG(KERNEL, "called");
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ void RenameFile(Service::Interface* self) {
|
||||||
src_filename_type, src_filename_size, src_file_path.DebugStr().c_str(),
|
src_filename_type, src_filename_size, src_file_path.DebugStr().c_str(),
|
||||||
dest_filename_type, dest_filename_size, dest_file_path.DebugStr().c_str());
|
dest_filename_type, dest_filename_size, dest_file_path.DebugStr().c_str());
|
||||||
|
|
||||||
cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path);
|
cmd_buff[1] = Kernel::RenameFileBetweenArchives(src_archive_handle, src_file_path, dest_archive_handle, dest_file_path).raw;
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "called");
|
DEBUG_LOG(KERNEL, "called");
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ void DeleteDirectory(Service::Interface* self) {
|
||||||
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
|
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s",
|
||||||
dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
||||||
|
|
||||||
cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path);
|
cmd_buff[1] = Kernel::DeleteDirectoryFromArchive(archive_handle, dir_path).raw;
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "called");
|
DEBUG_LOG(KERNEL, "called");
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ static void CreateDirectory(Service::Interface* self) {
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
|
||||||
|
|
||||||
cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path);
|
cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path).raw;
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "called");
|
DEBUG_LOG(KERNEL, "called");
|
||||||
}
|
}
|
||||||
|
@ -304,7 +304,7 @@ void RenameDirectory(Service::Interface* self) {
|
||||||
src_dirname_type, src_dirname_size, src_dir_path.DebugStr().c_str(),
|
src_dirname_type, src_dirname_size, src_dir_path.DebugStr().c_str(),
|
||||||
dest_dirname_type, dest_dirname_size, dest_dir_path.DebugStr().c_str());
|
dest_dirname_type, dest_dirname_size, dest_dir_path.DebugStr().c_str());
|
||||||
|
|
||||||
cmd_buff[1] = Kernel::RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path, dest_archive_handle, dest_dir_path);
|
cmd_buff[1] = Kernel::RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path, dest_archive_handle, dest_dir_path).raw;
|
||||||
|
|
||||||
DEBUG_LOG(KERNEL, "called");
|
DEBUG_LOG(KERNEL, "called");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue