summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorwwylele <wwylele@gmail.com>2016-10-14 09:29:09 +0200
committerwwylele <wwylele@gmail.com>2016-11-01 17:30:32 +0100
commit4dd8a831bd5ea32108db837754289ab42a2fa6ca (patch)
tree0aaf5cc1c8966446c4aa5d4e79d02641b7e4ba30 /src/core/file_sys
parentMerge pull request #2147 from Pringo/readme-donate (diff)
downloadyuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.tar
yuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.tar.gz
yuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.tar.bz2
yuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.tar.lz
yuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.tar.xz
yuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.tar.zst
yuzu-4dd8a831bd5ea32108db837754289ab42a2fa6ca.zip
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_backend.h28
-rw-r--r--src/core/file_sys/disk_archive.cpp50
-rw-r--r--src/core/file_sys/disk_archive.h14
-rw-r--r--src/core/file_sys/ivfc_archive.cpp31
-rw-r--r--src/core/file_sys/ivfc_archive.h14
5 files changed, 82 insertions, 55 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index 06b8f2ed7..58f6c150c 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -87,7 +87,7 @@ public:
* @return Opened file, or error code
*/
virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
- const Mode mode) const = 0;
+ const Mode& mode) const = 0;
/**
* Delete a file specified by its path
@@ -100,53 +100,53 @@ public:
* 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
+ * @return Result of the operation
*/
- virtual bool RenameFile(const Path& src_path, const Path& dest_path) const = 0;
+ virtual ResultCode RenameFile(const Path& src_path, const Path& dest_path) const = 0;
/**
* Delete a directory specified by its path
* @param path Path relative to the archive
- * @return Whether the directory could be deleted
+ * @return Result of the operation
*/
- virtual bool DeleteDirectory(const Path& path) const = 0;
+ virtual ResultCode 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
+ * @return Result of the operation
*/
- virtual bool DeleteDirectoryRecursively(const Path& path) const = 0;
+ virtual ResultCode DeleteDirectoryRecursively(const Path& path) const = 0;
/**
* Create a file specified by its path
* @param path Path relative to the Archive
* @param size The size of the new file, filled with zeroes
- * @return File creation result code
+ * @return Result of the operation
*/
virtual ResultCode CreateFile(const Path& path, u64 size) const = 0;
/**
* Create a directory specified by its path
* @param path Path relative to the archive
- * @return Whether the directory could be created
+ * @return Result of the operation
*/
- virtual bool CreateDirectory(const Path& path) const = 0;
+ virtual ResultCode CreateDirectory(const Path& path) const = 0;
/**
* 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
+ * @return Result of the operation
*/
- virtual bool RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
+ virtual ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
/**
* Open a directory specified by its path
* @param path Path relative to the archive
- * @return Opened directory, or nullptr
+ * @return Opened directory, or error code
*/
- virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0;
+ virtual ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const = 0;
/**
* Get the free space
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 2f05af361..ce6b9360b 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -16,7 +16,7 @@
namespace FileSys {
ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path,
- const Mode mode) const {
+ const Mode& mode) const {
LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex);
auto file = std::make_unique<DiskFile>(*this, path, mode);
ResultCode result = file->Open();
@@ -43,16 +43,28 @@ ResultCode DiskArchive::DeleteFile(const Path& path) const {
ErrorLevel::Status);
}
-bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
- return FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString());
+ResultCode DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
+ if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString()))
+ return RESULT_SUCCESS;
+
+ // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
+ // exist or similar. Verify.
+ return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+ ErrorSummary::NothingHappened, ErrorLevel::Status);
}
-bool DiskArchive::DeleteDirectory(const Path& path) const {
- return FileUtil::DeleteDir(mount_point + path.AsString());
+ResultCode DiskArchive::DeleteDirectory(const Path& path) const {
+ if (FileUtil::DeleteDir(mount_point + path.AsString()))
+ return RESULT_SUCCESS;
+ return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+ ErrorSummary::Canceled, ErrorLevel::Status);
}
-bool DiskArchive::DeleteDirectoryRecursively(const Path& path) const {
- return FileUtil::DeleteDirRecursively(mount_point + path.AsString());
+ResultCode DiskArchive::DeleteDirectoryRecursively(const Path& path) const {
+ if (FileUtil::DeleteDirRecursively(mount_point + path.AsString()))
+ return RESULT_SUCCESS;
+ return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+ ErrorSummary::Canceled, ErrorLevel::Status);
}
ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
@@ -81,20 +93,30 @@ ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
ErrorLevel::Info);
}
-bool DiskArchive::CreateDirectory(const Path& path) const {
- return FileUtil::CreateDir(mount_point + path.AsString());
+ResultCode DiskArchive::CreateDirectory(const Path& path) const {
+ if (FileUtil::CreateDir(mount_point + path.AsString()))
+ return RESULT_SUCCESS;
+ return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+ ErrorSummary::Canceled, ErrorLevel::Status);
}
-bool DiskArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
- return FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString());
+ResultCode DiskArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
+ if (FileUtil::Rename(mount_point + src_path.AsString(), mount_point + dest_path.AsString()))
+ return RESULT_SUCCESS;
+
+ // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
+ // exist or similar. Verify.
+ return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
+ ErrorSummary::NothingHappened, ErrorLevel::Status);
}
-std::unique_ptr<DirectoryBackend> DiskArchive::OpenDirectory(const Path& path) const {
+ResultVal<std::unique_ptr<DirectoryBackend>> DiskArchive::OpenDirectory(const Path& path) const {
LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str());
auto directory = std::make_unique<DiskDirectory>(*this, path);
if (!directory->Open())
- return nullptr;
- return std::move(directory);
+ return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
+ ErrorLevel::Permanent);
+ return MakeResult<std::unique_ptr<DirectoryBackend>>(std::move(directory));
}
u64 DiskArchive::GetFreeBytes() const {
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 59ebb2002..0edd87954 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -34,15 +34,15 @@ public:
}
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
- const Mode mode) const override;
+ const Mode& mode) const override;
ResultCode DeleteFile(const Path& path) const override;
- bool RenameFile(const Path& src_path, const Path& dest_path) const override;
- bool DeleteDirectory(const Path& path) const override;
- bool DeleteDirectoryRecursively(const Path& path) const override;
+ ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
+ ResultCode DeleteDirectory(const Path& path) const override;
+ ResultCode DeleteDirectoryRecursively(const Path& path) const override;
ResultCode CreateFile(const Path& path, u64 size) const override;
- bool CreateDirectory(const Path& path) const override;
- bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
- std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
+ ResultCode CreateDirectory(const Path& path) const override;
+ ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
+ ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
u64 GetFreeBytes() const override;
protected:
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index af59d296d..2735d2e3c 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -18,7 +18,7 @@ std::string IVFCArchive::GetName() const {
}
ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
- const Mode mode) const {
+ const Mode& mode) const {
return MakeResult<std::unique_ptr<FileBackend>>(
std::make_unique<IVFCFile>(romfs_file, data_offset, data_size));
}
@@ -31,22 +31,25 @@ ResultCode IVFCArchive::DeleteFile(const Path& path) const {
ErrorLevel::Status);
}
-bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
+ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
GetName().c_str());
- return false;
+ // TODO(wwylele): Use correct error code
+ return ResultCode(-1);
}
-bool IVFCArchive::DeleteDirectory(const Path& path) const {
+ResultCode IVFCArchive::DeleteDirectory(const Path& path) const {
LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
GetName().c_str());
- return false;
+ // TODO(wwylele): Use correct error code
+ return ResultCode(-1);
}
-bool IVFCArchive::DeleteDirectoryRecursively(const Path& path) const {
+ResultCode 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;
+ // TODO(wwylele): Use correct error code
+ return ResultCode(-1);
}
ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
@@ -57,20 +60,22 @@ ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
ErrorLevel::Permanent);
}
-bool IVFCArchive::CreateDirectory(const Path& path) const {
+ResultCode IVFCArchive::CreateDirectory(const Path& path) const {
LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).",
GetName().c_str());
- return false;
+ // TODO(wwylele): Use correct error code
+ return ResultCode(-1);
}
-bool IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
+ResultCode IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
GetName().c_str());
- return false;
+ // TODO(wwylele): Use correct error code
+ return ResultCode(-1);
}
-std::unique_ptr<DirectoryBackend> IVFCArchive::OpenDirectory(const Path& path) const {
- return std::make_unique<IVFCDirectory>();
+ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const {
+ return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<IVFCDirectory>());
}
u64 IVFCArchive::GetFreeBytes() const {
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 2fbb3a568..af6297e1f 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -33,15 +33,15 @@ public:
std::string GetName() const override;
ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
- const Mode mode) const override;
+ const Mode& mode) const override;
ResultCode DeleteFile(const Path& path) const override;
- bool RenameFile(const Path& src_path, const Path& dest_path) const override;
- bool DeleteDirectory(const Path& path) const override;
- bool DeleteDirectoryRecursively(const Path& path) const override;
+ ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override;
+ ResultCode DeleteDirectory(const Path& path) const override;
+ ResultCode DeleteDirectoryRecursively(const Path& path) const override;
ResultCode CreateFile(const Path& path, u64 size) const override;
- bool CreateDirectory(const Path& path) const override;
- bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
- std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
+ ResultCode CreateDirectory(const Path& path) const override;
+ ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
+ ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override;
u64 GetFreeBytes() const override;
protected: