From 72c1075402a1eb0132e540fc21407dc7d0ed65ff Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Sat, 13 Jan 2024 21:37:06 +0100 Subject: [PATCH] Reorder error handling in extdata FS::CreateFile (#7346) * Reorder error handling in extdata CreateFile * Apply suggestions --- src/core/file_sys/archive_extsavedata.cpp | 10 +--------- src/core/file_sys/savedata_archive.cpp | 9 +++++++-- src/core/file_sys/savedata_archive.h | 5 ++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index c2f5ed1a0e..65f13e7b27 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -92,7 +92,7 @@ class ExtSaveDataArchive : public SaveDataArchive { public: explicit ExtSaveDataArchive(const std::string& mount_point, std::unique_ptr delay_generator_) - : SaveDataArchive(mount_point) { + : SaveDataArchive(mount_point, false) { delay_generator = std::move(delay_generator_); } @@ -155,14 +155,6 @@ public: std::move(delay_generator)); } - Result CreateFile(const Path& path, u64 size) const override { - if (size == 0) { - LOG_ERROR(Service_FS, "Zero-size file is not supported"); - return ResultUnsupportedOpenFlags; - } - return SaveDataArchive::CreateFile(path, size); - } - private: ExtSaveDataArchive() = default; template diff --git a/src/core/file_sys/savedata_archive.cpp b/src/core/file_sys/savedata_archive.cpp index 894d9c2195..17380e6acb 100644 --- a/src/core/file_sys/savedata_archive.cpp +++ b/src/core/file_sys/savedata_archive.cpp @@ -232,8 +232,13 @@ Result SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) const { } if (size == 0) { - FileUtil::CreateEmptyFile(full_path); - return ResultSuccess; + if (allow_zero_size_create) { + FileUtil::CreateEmptyFile(full_path); + return ResultSuccess; + } else { + LOG_DEBUG(Service_FS, "Zero-size file is not supported"); + return ResultUnsupportedOpenFlags; + } } FileUtil::IOFile file(full_path, "wb"); diff --git a/src/core/file_sys/savedata_archive.h b/src/core/file_sys/savedata_archive.h index e243dc1c01..f72f924f11 100644 --- a/src/core/file_sys/savedata_archive.h +++ b/src/core/file_sys/savedata_archive.h @@ -15,7 +15,8 @@ namespace FileSys { /// Archive backend for general save data archive type (SaveData and SystemSaveData) class SaveDataArchive : public ArchiveBackend { public: - explicit SaveDataArchive(const std::string& mount_point_) : mount_point(mount_point_) {} + explicit SaveDataArchive(const std::string& mount_point_, bool allow_zero_size_create_ = true) + : mount_point(mount_point_), allow_zero_size_create(allow_zero_size_create_) {} std::string GetName() const override { return "SaveDataArchive: " + mount_point; @@ -35,6 +36,7 @@ public: protected: std::string mount_point; + bool allow_zero_size_create; SaveDataArchive() = default; private: @@ -42,6 +44,7 @@ private: void serialize(Archive& ar, const unsigned int) { ar& boost::serialization::base_object(*this); ar& mount_point; + ar& allow_zero_size_create; } friend class boost::serialization::access; };