diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-09-28 18:32:54 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-09-28 18:32:58 +0300 |
commit | 34ba6968b2d4b4803652c3c109963a2de4b070ee (patch) | |
tree | 26cf05b9a2e829a76567f91a52428dae4870a6ca /source/blender | |
parent | f17ca53cdd2f3e3f4ccfcae404deebb02ead158d (diff) |
Cleanup: asset catalog service, remove obsolete `write_to_disk` function
Remove `AssetCatalogService::write_to_disk()` function. It has been
superseded by `write_to_disk_on_blendfile_save()`; the handful of test
functions that called the old function have been adjusted to use the
new one.
No functional changes to Blender itself.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_asset_catalog.hh | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/asset_catalog.cc | 23 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/asset_catalog_test.cc | 10 |
3 files changed, 7 insertions, 37 deletions
diff --git a/source/blender/blenkernel/BKE_asset_catalog.hh b/source/blender/blenkernel/BKE_asset_catalog.hh index 9b8b99f8f6d..cae476708cd 100644 --- a/source/blender/blenkernel/BKE_asset_catalog.hh +++ b/source/blender/blenkernel/BKE_asset_catalog.hh @@ -65,15 +65,6 @@ class AssetCatalogService { void load_from_disk(const CatalogFilePath &file_or_directory_path); /** - * Write the catalog definitions to disk. - * The provided directory path is only used when there is no CDF loaded from disk yet but assets - * still have to be saved. - * - * Return true on success, which either means there were no in-memory categories to save, or the - * save was successful. */ - bool write_to_disk(const CatalogFilePath &directory_for_new_files); - - /** * Write the catalog definitions to disk in response to the blend file being saved. * * The location where the catalogs are saved is variable, and depends on the location of the @@ -90,7 +81,7 @@ class AssetCatalogService { * * Return true on success, which either means there were no in-memory categories to save, * or the save was successful. */ - bool write_to_disk_on_blendfile_save(const char *blend_file_path); + bool write_to_disk_on_blendfile_save(const CatalogFilePath &blend_file_path); /** * Merge on-disk changes into the in-memory asset catalogs. diff --git a/source/blender/blenkernel/intern/asset_catalog.cc b/source/blender/blenkernel/intern/asset_catalog.cc index 05e27a93621..d98d83c477f 100644 --- a/source/blender/blenkernel/intern/asset_catalog.cc +++ b/source/blender/blenkernel/intern/asset_catalog.cc @@ -268,31 +268,10 @@ void AssetCatalogService::merge_from_disk_before_writing() catalog_parsed_callback); } -bool AssetCatalogService::write_to_disk(const CatalogFilePath &directory_for_new_files) +bool AssetCatalogService::write_to_disk_on_blendfile_save(const CatalogFilePath &blend_file_path) { /* TODO(Sybren): expand to support multiple CDFs. */ - if (!catalog_definition_file_) { - if (catalogs_.is_empty() && deleted_catalogs_.is_empty()) { - /* Avoid saving anything, when there is nothing to save. */ - return true; /* Writing nothing when there is nothing to write is still a success. */ - } - - /* A CDF has to be created to contain all current in-memory catalogs. */ - const CatalogFilePath cdf_path = asset_definition_default_file_path_from_dir( - directory_for_new_files); - catalog_definition_file_ = construct_cdf_in_memory(cdf_path); - } - - merge_from_disk_before_writing(); - return catalog_definition_file_->write_to_disk(); -} - -bool AssetCatalogService::write_to_disk_on_blendfile_save(const char *blend_file_path) -{ - /* TODO(Sybren): deduplicate this and write_to_disk(...); maybe the latter function isn't even - * necessary any more. */ - /* - Already loaded a CDF from disk? -> Always write to that file. */ if (this->catalog_definition_file_) { merge_from_disk_before_writing(); diff --git a/source/blender/blenkernel/intern/asset_catalog_test.cc b/source/blender/blenkernel/intern/asset_catalog_test.cc index b36c15940b8..a833e7903fa 100644 --- a/source/blender/blenkernel/intern/asset_catalog_test.cc +++ b/source/blender/blenkernel/intern/asset_catalog_test.cc @@ -403,7 +403,7 @@ TEST_F(AssetCatalogTest, no_writing_empty_files) { const CatalogFilePath temp_lib_root = create_temp_path(); AssetCatalogService service(temp_lib_root); - service.write_to_disk(temp_lib_root); + service.write_to_disk_on_blendfile_save(temp_lib_root + "phony.blend"); const CatalogFilePath default_cdf_path = temp_lib_root + AssetCatalogService::DEFAULT_CATALOG_FILENAME; @@ -574,7 +574,7 @@ TEST_F(AssetCatalogTest, create_first_catalog_from_scratch) EXPECT_FALSE(BLI_exists(temp_lib_root.c_str())); /* Writing to disk should create the directory + the default file. */ - service.write_to_disk(temp_lib_root); + service.write_to_disk_on_blendfile_save(temp_lib_root + "phony.blend"); EXPECT_TRUE(BLI_is_dir(temp_lib_root.c_str())); const CatalogFilePath definition_file_path = temp_lib_root + "/" + @@ -625,7 +625,7 @@ TEST_F(AssetCatalogTest, create_catalog_after_loading_file) << "expecting newly added catalog to not yet be saved to " << temp_lib_root; /* Write and reload the catalog file. */ - service.write_to_disk(temp_lib_root); + service.write_to_disk_on_blendfile_save(temp_lib_root + "phony.blend"); AssetCatalogService reloaded_service(temp_lib_root); reloaded_service.load_from_disk(); EXPECT_NE(nullptr, reloaded_service.find_catalog(UUID_POSES_ELLIE)) @@ -758,7 +758,7 @@ TEST_F(AssetCatalogTest, merge_catalog_files) ASSERT_EQ(0, BLI_copy(modified_cdf_file.c_str(), temp_cdf_file.c_str())); // Overwrite the modified file. This should merge the on-disk file with our catalogs. - service.write_to_disk(cdf_dir); + service.write_to_disk_on_blendfile_save(cdf_dir + "phony.blend"); AssetCatalogService loaded_service(cdf_dir); loaded_service.load_from_disk(); @@ -788,7 +788,7 @@ TEST_F(AssetCatalogTest, backups) AssetCatalogService service(cdf_dir); service.load_from_disk(); service.delete_catalog(UUID_POSES_ELLIE); - service.write_to_disk(cdf_dir); + service.write_to_disk_on_blendfile_save(cdf_dir + "phony.blend"); const CatalogFilePath backup_path = writable_cdf_file + "~"; ASSERT_TRUE(BLI_is_file(backup_path.c_str())); |