From 241697b8ba494abb9196da03d0c9b88c3e2e7b73 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 6 Mar 2020 04:44:49 -0800 Subject: [PATCH] ncm: use R_SUCCEED_IF --- .../ncm/source/ncm_content_manager_impl.cpp | 16 ++++++++-------- .../source/ncm_content_meta_database_impl.cpp | 8 ++++---- .../ncm/source/ncm_content_storage_impl.cpp | 6 ++++-- .../ncm/source/ncm_placeholder_accessor.cpp | 4 ++-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/stratosphere/ncm/source/ncm_content_manager_impl.cpp b/stratosphere/ncm/source/ncm_content_manager_impl.cpp index 7bbc8f550..c65caaf7f 100644 --- a/stratosphere/ncm/source/ncm_content_manager_impl.cpp +++ b/stratosphere/ncm/source/ncm_content_manager_impl.cpp @@ -81,7 +81,7 @@ namespace ams::ncm { /* Obtain the existing flags. */ R_TRY(fs::GetSaveDataFlags(std::addressof(cur_flags), BuiltInSystemSaveDataId)); - + /* Update the flags if needed. */ if (cur_flags != BuiltInSystemSaveDataFlags) { R_TRY(fs::SetSaveDataFlags(BuiltInSystemSaveDataId, fs::SaveDataSpaceId::System, BuiltInSystemSaveDataFlags)); @@ -222,8 +222,8 @@ namespace ams::ncm { Result ContentManagerImpl::Initialize() { std::scoped_lock lk(this->mutex); - /* Already initialized. */ - R_UNLESS(!this->initialized, ResultSuccess()); + /* Check if we've already initialized. */ + R_SUCCEED_IF(this->initialized); /* Clear storage id for all roots. */ for (auto &root : this->content_storage_roots) { @@ -289,7 +289,7 @@ namespace ams::ncm { /* Ensure the content storage root's path exists. */ R_TRY(impl::EnsureDirectoryRecursively(root->path)); - + /* Initialize content and placeholder directories for the root. */ R_TRY(ContentStorageImpl::InitializeBase(root->path)); @@ -312,7 +312,7 @@ namespace ams::ncm { /* Ensure the content meta database root's path exists. */ R_TRY(impl::EnsureDirectoryRecursively(root->path)); - /* Commit our changes. */ + /* Commit our changes. */ R_TRY(fs::CommitSaveData(root->mount_name)); return ResultSuccess(); @@ -342,7 +342,7 @@ namespace ams::ncm { Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) { /* Game card content meta databases will always be valid. */ - R_UNLESS(storage_id != StorageId::GameCard, ResultSuccess()); + R_SUCCEED_IF(storage_id == StorageId::GameCard); std::scoped_lock lk(this->mutex); @@ -441,7 +441,7 @@ namespace ams::ncm { R_TRY(this->GetContentStorageRoot(std::addressof(root), storage_id)); /* Check if the storage is already activated. */ - R_UNLESS(root->content_storage == nullptr, ResultSuccess()); + R_SUCCEED_IF(root->content_storage != nullptr); /* Mount based on the storage type. */ if (storage_id == StorageId::GameCard) { @@ -511,7 +511,7 @@ namespace ams::ncm { R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id)); /* Already activated. */ - R_UNLESS(root->content_meta_database == nullptr, ResultSuccess()); + R_SUCCEED_IF(root->content_meta_database != nullptr); /* Make a new kvs. */ root->kvs.emplace(); diff --git a/stratosphere/ncm/source/ncm_content_meta_database_impl.cpp b/stratosphere/ncm/source/ncm_content_meta_database_impl.cpp index ac36533a3..867c368f8 100644 --- a/stratosphere/ncm/source/ncm_content_meta_database_impl.cpp +++ b/stratosphere/ncm/source/ncm_content_meta_database_impl.cpp @@ -215,9 +215,12 @@ namespace ams::ncm { /* Check if keys are present. */ for (size_t i = 0; i < keys.GetSize(); i++) { + /* Check if we have the current key. */ bool has; R_TRY(this->Has(std::addressof(has), keys[i])); - R_UNLESS(has, ResultSuccess()); + + /* If we don't, then we can early return because we don't have all. */ + R_SUCCEED_IF(!has); } *out = true; @@ -288,9 +291,6 @@ namespace ams::ncm { out_orphaned[i] = true; } - /* If key value store is empty, all content is orphaned. */ - R_UNLESS(this->kvs->GetCount() != 0, ResultSuccess()); - auto IsOrphanedContent = [](const sf::InArray &list, const ncm::ContentId &id) ALWAYS_INLINE_LAMBDA { /* Check if any input content ids match our found content id. */ for (size_t i = 0; i < list.GetSize(); i++) { diff --git a/stratosphere/ncm/source/ncm_content_storage_impl.cpp b/stratosphere/ncm/source/ncm_content_storage_impl.cpp index ccf82ef49..d2864f04c 100644 --- a/stratosphere/ncm/source/ncm_content_storage_impl.cpp +++ b/stratosphere/ncm/source/ncm_content_storage_impl.cpp @@ -56,7 +56,8 @@ namespace ams::ncm { template Result TraverseDirectory(bool *out_should_continue, const char *root_path, int max_level, F f) { - R_UNLESS(max_level > 0, ResultSuccess()); + /* If the level is zero, we're done. */ + R_SUCCEED_IF(max_level <= 0); /* Retry traversal upon request. */ bool retry_dir_read = true; @@ -230,7 +231,8 @@ namespace ams::ncm { } Result ContentStorageImpl::OpenContentIdFile(ContentId content_id) { - R_UNLESS(this->cached_content_id != content_id, ResultSuccess()); + /* If the file is the currently cached one, we've nothing to do. */ + R_SUCCEED_IF(this->cached_content_id == content_id); /* Close any cached file. */ this->InvalidateFileCache(); diff --git a/stratosphere/ncm/source/ncm_placeholder_accessor.cpp b/stratosphere/ncm/source/ncm_placeholder_accessor.cpp index 70fde768b..2c7d42098 100644 --- a/stratosphere/ncm/source/ncm_placeholder_accessor.cpp +++ b/stratosphere/ncm/source/ncm_placeholder_accessor.cpp @@ -84,7 +84,7 @@ namespace ams::ncm { Result PlaceHolderAccessor::Open(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) { /* Try to load from the cache. */ - R_UNLESS(!this->LoadFromCache(out_handle, placeholder_id), ResultSuccess()); + R_SUCCEED_IF(this->LoadFromCache(out_handle, placeholder_id)); /* Make the path of the placeholder. */ PathString placeholder_path; @@ -231,7 +231,7 @@ namespace ams::ncm { /* Attempt to find the placeholder in the cache. */ fs::FileHandle handle; auto found = this->LoadFromCache(std::addressof(handle), placeholder_id); - + if (found) { /* Renew the entry in the cache. */ this->StoreToCache(placeholder_id, handle);