From 31035ae19f3f9f957287ee92349f3a28e4557d8f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Oct 2025 10:40:32 +0000 Subject: [PATCH] Fix #148189: linking relative paths fails to resolve path Resolve regression in [0] which would attempt to use `//` when loading library files. Expand the directories before use. Ref !148193 [0]: 7bc7b7743bb14781aa864c1625e19192ad9a36fd --- .../windowmanager/intern/wm_files_link.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/source/blender/windowmanager/intern/wm_files_link.cc b/source/blender/windowmanager/intern/wm_files_link.cc index 28fac0f93be..9f5addfc7ed 100644 --- a/source/blender/windowmanager/intern/wm_files_link.cc +++ b/source/blender/windowmanager/intern/wm_files_link.cc @@ -201,6 +201,7 @@ static bool wm_link_append_item_poll(ReportList *reports, static wmOperatorStatus wm_link_append_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + const char *blendfile_path = BKE_main_blendfile_path(bmain); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); PropertyRNA *prop; @@ -212,6 +213,9 @@ static wmOperatorStatus wm_link_append_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filename", relname); RNA_string_get(op->ptr, "directory", root); + if (BLI_path_is_rel(root)) { + BLI_path_abs(root, blendfile_path); + } BLI_path_join(filepath, sizeof(filepath), root, relname); @@ -220,7 +224,6 @@ static wmOperatorStatus wm_link_append_exec(bContext *C, wmOperator *op) filepath, libname, &group, &name); { - const char *blendfile_path = BKE_main_blendfile_path(bmain); if (blendfile_path[0] != '\0') { /* NOTE: Need to also check `filepath`, as typically `libname` is an empty string here * (when trying to append from current file from the file-browser e.g.). */ @@ -528,6 +531,7 @@ void WM_OT_append(wmOperatorType *ot) static wmOperatorStatus wm_id_linked_relocate_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + const char *blendfile_path = BKE_main_blendfile_path(bmain); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); BlendfileLinkAppendContext *lapp_context; @@ -537,6 +541,9 @@ static wmOperatorStatus wm_id_linked_relocate_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filename", relname); RNA_string_get(op->ptr, "directory", root); + if (BLI_path_is_rel(root)) { + BLI_path_abs(root, blendfile_path); + } BLI_path_join(filepath, sizeof(filepath), root, relname); @@ -545,7 +552,6 @@ static wmOperatorStatus wm_id_linked_relocate_exec(bContext *C, wmOperator *op) filepath, libname, &group, &name); { - const char *blendfile_path = BKE_main_blendfile_path(bmain); if (blendfile_path[0] != '\0') { /* NOTE: Need to also check `filepath`, as typically `libname` is an empty string here * (when trying to append from current file from the file-browser e.g.). */ @@ -883,6 +889,7 @@ void WM_lib_reload(Library *lib, bContext *C, ReportList *reports) static wmOperatorStatus wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload) { Main *bmain = CTX_data_main(C); + const char *blendfile_path = BKE_main_blendfile_path(bmain); char lib_name[MAX_NAME]; RNA_string_get(op->ptr, "library", lib_name); @@ -909,8 +916,11 @@ static wmOperatorStatus wm_lib_relocate_exec_do(bContext *C, wmOperator *op, boo return OPERATOR_CANCELLED; } - RNA_string_get(op->ptr, "directory", root); RNA_string_get(op->ptr, "filename", libname); + RNA_string_get(op->ptr, "directory", root); + if (BLI_path_is_rel(root)) { + BLI_path_abs(root, blendfile_path); + } if (!BKE_blendfile_extension_check(libname)) { BKE_report(op->reports, RPT_ERROR, "Not a library"); @@ -929,7 +939,6 @@ static wmOperatorStatus wm_lib_relocate_exec_do(bContext *C, wmOperator *op, boo } { - const char *blendfile_path = BKE_main_blendfile_path(bmain); if ((blendfile_path[0] != '\0') && (BLI_path_cmp(blendfile_path, filepath) == 0)) { BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,