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() {
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) {
@ -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();

View File

@ -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<ContentId> &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++) {

View File

@ -56,7 +56,8 @@ namespace ams::ncm {
template<typename 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. */
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();

View File

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