BPath traversing: allow skipping weak library references

Add flag to `BKE_bpath_traverse_id()` and friends to skip weak
references (see below). This makes a distinction between "this blend
file depends on that file" and "this blend file references that file,
but doesn't directly use its data". This distinction is for the Asset
Bundle install operator, which refuses to copy the blend file when it's
not self-contained.

Weak references are those that are not directly used by the blend file,
but are still present to allow path rewriting. For example, when an
Asset is loaded its originating blend file is saved in
`ID::library_weak_reference`; this reference is purely for deduplication
purposes, and not for actually loading any data.

Reviewed by: mont29, brecht

Differential Revision: https://developer.blender.org/D13412
This commit is contained in:
Sybren A. Stüvel
2021-11-30 10:41:23 +01:00
parent e7ae9f493a
commit c12d8a72ce
3 changed files with 11 additions and 3 deletions

View File

@@ -70,6 +70,12 @@ enum {
BKE_BPATH_TRAVERSE_SKIP_MULTIFILE = (1 << 3),
/* reload data (when the path is edited) */
BKE_BPATH_TRAVERSE_RELOAD_EDITED = (1 << 4),
/* Skip weak reference paths. Those paths are typically 'nice to have' extra information, but are
* not used as actual source of data by the current .blend file.
*
* NOTE: Currently this only concerns the weak reference to a library file stored in
* `ID::library_weak_reference`. */
BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES = (1 << 5),
};
/* high level funcs */

View File

@@ -586,7 +586,8 @@ void BKE_bpath_traverse_id(
return;
}
if (id->library_weak_reference != NULL) {
if (id->library_weak_reference != NULL &&
(flag & BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES) == 0) {
rewrite_path_fixed(
id->library_weak_reference->library_filepath, visit_cb, absbase, bpath_user_data);
}

View File

@@ -912,8 +912,9 @@ static bool has_external_files(Main *bmain, struct ReportList *reports)
BKE_bpath_traverse_main(
bmain,
&external_file_check_callback,
BKE_BPATH_TRAVERSE_SKIP_PACKED /* Packed files are fine. */
| BKE_BPATH_TRAVERSE_SKIP_MULTIFILE /* Only report multifiles once, it's enough. */,
BKE_BPATH_TRAVERSE_SKIP_PACKED /* Packed files are fine. */
| BKE_BPATH_TRAVERSE_SKIP_MULTIFILE /* Only report multifiles once, it's enough. */
| BKE_BPATH_TRAVERSE_SKIP_WEAK_REFERENCES /* Only care about actually used files. */,
&callback_info);
return callback_info.external_file_found;
}