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.
This commit is contained in:
Sybren A. Stüvel 2021-09-28 17:32:54 +02:00
parent f17ca53cdd
commit 34ba6968b2
3 changed files with 7 additions and 37 deletions

View File

@ -64,15 +64,6 @@ class AssetCatalogService {
/** Load asset catalog definitions from the given file or directory. */
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.
*
@ -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.

View File

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

View File

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