Reorder error handling in extdata FS::CreateFile (#7346)

* Reorder error handling in extdata CreateFile

* Apply suggestions
This commit is contained in:
PabloMK7 2024-01-13 21:37:06 +01:00 committed by GitHub
parent 30c53c9509
commit 72c1075402
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View File

@ -92,7 +92,7 @@ class ExtSaveDataArchive : public SaveDataArchive {
public:
explicit ExtSaveDataArchive(const std::string& mount_point,
std::unique_ptr<DelayGenerator> 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 <class Archive>

View File

@ -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");

View File

@ -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<ArchiveBackend>(*this);
ar& mount_point;
ar& allow_zero_size_create;
}
friend class boost::serialization::access;
};