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),