ncm: use R_SUCCEED_IF

This commit is contained in:
Michael Scire 2020-03-06 04:44:49 -08:00
parent 510a764350
commit 241697b8ba
4 changed files with 18 additions and 16 deletions

View File

@ -222,8 +222,8 @@ namespace ams::ncm {
Result ContentManagerImpl::Initialize() { Result ContentManagerImpl::Initialize() {
std::scoped_lock lk(this->mutex); std::scoped_lock lk(this->mutex);
/* Already initialized. */ /* Check if we've already initialized. */
R_UNLESS(!this->initialized, ResultSuccess()); R_SUCCEED_IF(this->initialized);
/* Clear storage id for all roots. */ /* Clear storage id for all roots. */
for (auto &root : this->content_storage_roots) { for (auto &root : this->content_storage_roots) {
@ -342,7 +342,7 @@ namespace ams::ncm {
Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) { Result ContentManagerImpl::VerifyContentMetaDatabase(StorageId storage_id) {
/* Game card content meta databases will always be valid. */ /* 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); std::scoped_lock lk(this->mutex);
@ -441,7 +441,7 @@ namespace ams::ncm {
R_TRY(this->GetContentStorageRoot(std::addressof(root), storage_id)); R_TRY(this->GetContentStorageRoot(std::addressof(root), storage_id));
/* Check if the storage is already activated. */ /* 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. */ /* Mount based on the storage type. */
if (storage_id == StorageId::GameCard) { if (storage_id == StorageId::GameCard) {
@ -511,7 +511,7 @@ namespace ams::ncm {
R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id)); R_TRY(this->GetContentMetaDatabaseRoot(&root, storage_id));
/* Already activated. */ /* Already activated. */
R_UNLESS(root->content_meta_database == nullptr, ResultSuccess()); R_SUCCEED_IF(root->content_meta_database != nullptr);
/* Make a new kvs. */ /* Make a new kvs. */
root->kvs.emplace(); root->kvs.emplace();

View File

@ -215,9 +215,12 @@ namespace ams::ncm {
/* Check if keys are present. */ /* Check if keys are present. */
for (size_t i = 0; i < keys.GetSize(); i++) { for (size_t i = 0; i < keys.GetSize(); i++) {
/* Check if we have the current key. */
bool has; bool has;
R_TRY(this->Has(std::addressof(has), keys[i])); 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; *out = true;
@ -288,9 +291,6 @@ namespace ams::ncm {
out_orphaned[i] = true; 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<ContentId> &list, const ncm::ContentId &id) ALWAYS_INLINE_LAMBDA { auto IsOrphanedContent = [](const sf::InArray<ContentId> &list, const ncm::ContentId &id) ALWAYS_INLINE_LAMBDA {
/* Check if any input content ids match our found content id. */ /* Check if any input content ids match our found content id. */
for (size_t i = 0; i < list.GetSize(); i++) { for (size_t i = 0; i < list.GetSize(); i++) {

View File

@ -56,7 +56,8 @@ namespace ams::ncm {
template<typename F> template<typename F>
Result TraverseDirectory(bool *out_should_continue, const char *root_path, int max_level, F f) { 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. */ /* Retry traversal upon request. */
bool retry_dir_read = true; bool retry_dir_read = true;
@ -230,7 +231,8 @@ namespace ams::ncm {
} }
Result ContentStorageImpl::OpenContentIdFile(ContentId content_id) { 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. */ /* Close any cached file. */
this->InvalidateFileCache(); this->InvalidateFileCache();

View File

@ -84,7 +84,7 @@ namespace ams::ncm {
Result PlaceHolderAccessor::Open(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) { Result PlaceHolderAccessor::Open(fs::FileHandle *out_handle, PlaceHolderId placeholder_id) {
/* Try to load from the cache. */ /* 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. */ /* Make the path of the placeholder. */
PathString placeholder_path; PathString placeholder_path;