diff --git a/stratosphere/ncm/source/impl/ncm_content_manager.cpp b/stratosphere/ncm/source/impl/ncm_content_manager.cpp index 6d3d6af74..7138787ee 100644 --- a/stratosphere/ncm/source/impl/ncm_content_manager.cpp +++ b/stratosphere/ncm/source/impl/ncm_content_manager.cpp @@ -508,7 +508,9 @@ namespace sts::ncm::impl { Unmount(entry->mount_point); }; - R_TRY(EnsureDirectoryRecursively(entry->mount_point)); + D_LOG("storage id: 0x%x\n", storage_id); + D_LOG("creating %s\n", entry->meta_path); + R_TRY(EnsureDirectoryRecursively(entry->meta_path)); R_TRY(fsdevCommitDevice(entry->mount_point)); return ResultSuccess; @@ -517,6 +519,8 @@ namespace sts::ncm::impl { Result VerifyContentMetaDatabase(StorageId storage_id) { std::scoped_lock lk(g_mutex); + D_LOG("storage id: 0x%x\n", storage_id); + if (storage_id == StorageId::GameCard) { return ResultSuccess; } @@ -538,16 +542,19 @@ namespace sts::ncm::impl { mounted_save_data = true; } + ON_SCOPE_EXIT { + if (mounted_save_data) { + Unmount(entry->mount_point); + } + }; + bool has_meta_path = false; R_TRY(HasDirectory(&has_meta_path, entry->meta_path)); if (!has_meta_path) { + D_LOG("Meta path %s not found\n", entry->meta_path); return ResultNcmInvalidContentMetaDatabase; } - if (mounted_save_data) { - Unmount(entry->mount_point); - } - return ResultSuccess; } @@ -657,8 +664,12 @@ namespace sts::ncm::impl { if (storage_id != StorageId::GameCard) { R_TRY(MountSystemSaveData(entry->mount_point, entry->save_meta.space_id, entry->save_meta.id)); auto mount_guard = SCOPE_GUARD { Unmount(entry->mount_point); }; + D_LOG("storage_id 0x%x\n", storage_id); + D_LOG("init\n"); R_TRY(entry->kvs->Initialize(entry->meta_path, entry->max_content_metas)); + D_LOG("load\n"); R_TRY(entry->kvs->Load()); + D_LOG("loaded\n"); auto content_meta_database = std::make_shared(&*entry->kvs, entry->mount_point); entry->content_meta_database = std::move(content_meta_database); diff --git a/stratosphere/ncm/source/ncm_fs.cpp b/stratosphere/ncm/source/ncm_fs.cpp index 7c8f2b7a1..58b6f757b 100644 --- a/stratosphere/ncm/source/ncm_fs.cpp +++ b/stratosphere/ncm/source/ncm_fs.cpp @@ -170,10 +170,18 @@ namespace sts::ncm { } Result EnsureDirectoryRecursively(const char* dir_path) { - return EnsureRecursively(dir_path, true); + R_TRY(EnsureRecursively(dir_path)); + if (mkdir(dir_path, S_IRWXU) == -1) { + R_TRY_CATCH(fsdevGetLastResult()) { + R_CATCH(ResultFsPathAlreadyExists) { + /* If the path already exists, that's okay. Anything else is an error. */ + } + } R_END_TRY_CATCH; + } + return ResultSuccess; } - Result EnsureRecursively(const char* path, bool is_dir) { + Result EnsureRecursively(const char* path) { if (!path) { return ResultFsNullptrArgument; } @@ -201,6 +209,14 @@ namespace sts::ncm { working_path_buf[i + 1] = '/'; } } + + if (mkdir(working_path_buf + 1, S_IRWXU) == -1) { + R_TRY_CATCH(fsdevGetLastResult()) { + R_CATCH(ResultFsPathAlreadyExists) { + /* If the path already exists, that's okay. Anything else is an error. */ + } + } R_END_TRY_CATCH; + } } } else { return ResultNcmAllocationFailed; @@ -210,7 +226,7 @@ namespace sts::ncm { } Result EnsureParentDirectoryRecursively(const char* path) { - return EnsureRecursively(path, false); + return EnsureRecursively(path); } Result GetGameCardHandle(FsGameCardHandle* out_handle) { diff --git a/stratosphere/ncm/source/ncm_fs.hpp b/stratosphere/ncm/source/ncm_fs.hpp index 4e857406d..347c323fb 100644 --- a/stratosphere/ncm/source/ncm_fs.hpp +++ b/stratosphere/ncm/source/ncm_fs.hpp @@ -34,7 +34,7 @@ namespace sts::ncm { Result EnsureContentAndPlaceHolderRoot(const char* root_path); Result EnsureDirectoryRecursively(const char* dir_path); - Result EnsureRecursively(const char* path, bool is_dir); + Result EnsureRecursively(const char* path); /* Create all parent directories for a file path */ Result EnsureParentDirectoryRecursively(const char* path);