From 8717036405f51d56a01e53ec2b2e00772f345a32 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 16 Jun 2025 12:05:28 +0200 Subject: [PATCH] Fix #140426: Saving new file creates empty catalog file next to .blend When initially saving a file, we would now always create a catalog definition file that would be writted to disk on file save. This shouldn't be done if there are no new catalogs to write. --- source/blender/asset_system/intern/asset_catalog.cc | 4 +--- .../blender/asset_system/intern/asset_catalog_collection.cc | 5 +++++ .../blender/asset_system/intern/asset_catalog_collection.hh | 4 ++++ source/blender/asset_system/intern/asset_library_service.cc | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/blender/asset_system/intern/asset_catalog.cc b/source/blender/asset_system/intern/asset_catalog.cc index 572fbc7bb38..806ac8a4f7e 100644 --- a/source/blender/asset_system/intern/asset_catalog.cc +++ b/source/blender/asset_system/intern/asset_catalog.cc @@ -488,9 +488,7 @@ bool AssetCatalogService::write_to_disk_ex(const CatalogFilePath &blend_file_pat return catalog_collection_->catalog_definition_file_->write_to_disk(); } - if (catalog_collection_->catalogs_.is_empty() && - catalog_collection_->deleted_catalogs_.is_empty()) - { + if (catalog_collection_->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. */ } diff --git a/source/blender/asset_system/intern/asset_catalog_collection.cc b/source/blender/asset_system/intern/asset_catalog_collection.cc index 03d4e48fbb8..bc17db79cfc 100644 --- a/source/blender/asset_system/intern/asset_catalog_collection.cc +++ b/source/blender/asset_system/intern/asset_catalog_collection.cc @@ -12,6 +12,11 @@ namespace blender::asset_system { +bool AssetCatalogCollection::is_empty() const +{ + return catalogs_.is_empty() && deleted_catalogs_.is_empty(); +} + std::unique_ptr AssetCatalogCollection::deep_copy() const { auto copy = std::make_unique(); diff --git a/source/blender/asset_system/intern/asset_catalog_collection.hh b/source/blender/asset_system/intern/asset_catalog_collection.hh index 546d7e33d6f..071edd5e03f 100644 --- a/source/blender/asset_system/intern/asset_catalog_collection.hh +++ b/source/blender/asset_system/intern/asset_catalog_collection.hh @@ -44,6 +44,10 @@ class AssetCatalogCollection { AssetCatalogCollection(const AssetCatalogCollection &other) = delete; AssetCatalogCollection(AssetCatalogCollection &&other) noexcept = default; + /** Check if this contains any catalogs or deleted catalogs. Doesn't check if a CDF is present. + */ + bool is_empty() const; + std::unique_ptr deep_copy() const; using OnDuplicateCatalogIdFn = FunctionRef; diff --git a/source/blender/asset_system/intern/asset_library_service.cc b/source/blender/asset_system/intern/asset_library_service.cc index cc722b4b15d..39ccd27b4b3 100644 --- a/source/blender/asset_system/intern/asset_library_service.cc +++ b/source/blender/asset_system/intern/asset_library_service.cc @@ -262,7 +262,9 @@ AssetLibrary *AssetLibraryService::move_runtime_current_file_into_on_disk_librar "new on-disk library shouldn't have catalog definition files - root path " "changed, so they would have to be relocated"); - { + /* Create a CDF with the runtime catalogs that on-disk catalogs can be merged into. Only do if + * there's catalogs to write, otherwise we create empty CDFs on disk on every new .blend save. */ + if (!catalog_service.catalog_collection_->is_empty()) { char asset_lib_cdf_path[PATH_MAX]; BLI_path_join(asset_lib_cdf_path, sizeof(asset_lib_cdf_path),