[Bf-blender-cvs] [83349294b12] blender-v3.2-release: Fix T98201: Corrution of filepaths in some case during 'make relative' process.

Bastien Montagne noreply at git.blender.org
Tue May 17 17:34:40 CEST 2022


Commit: 83349294b12f904bc1295c53e0242ea92c593c93
Author: Bastien Montagne
Date:   Tue May 17 17:32:23 2022 +0200
Branches: blender-v3.2-release
https://developer.blender.org/rB83349294b12f904bc1295c53e0242ea92c593c93

Fix T98201: Corrution of filepaths in some case during 'make relative' process.

We need to ensure `Main.filepath` is consistent with the current path
where we are saving the .blend file, otherwise some path processing code
can produce invalid results (happens with e.g. the code syncing the two
path storages in Library IDs).

===================================================================

M	source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 2ae660ab1b6..22db54d7609 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1349,7 +1349,6 @@ bool BLO_write_file(Main *mainvar,
 
   /* Remapping of relative paths to new file location. */
   if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) {
-
     if (remap_mode == BLO_WRITE_PATH_REMAP_RELATIVE) {
       /* Make all relative as none of the existing paths can be relative in an unsaved document. */
       if (relbase_valid == false) {
@@ -1388,6 +1387,13 @@ bool BLO_write_file(Main *mainvar,
     }
 
     if (remap_mode != BLO_WRITE_PATH_REMAP_NONE) {
+      /* Some path processing (e.g. with libraries) may use the current `main->filepath`, if this
+       * is not matching the path currently used for saving, unexpected paths corruptions can
+       * happen. See T98201. */
+      char mainvar_filepath_orig[FILE_MAX];
+      STRNCPY(mainvar_filepath_orig, mainvar->filepath);
+      STRNCPY(mainvar->filepath, filepath);
+
       /* Check if we need to backup and restore paths. */
       if (UNLIKELY(use_save_as_copy)) {
         path_list_backup = BKE_bpath_list_backup(mainvar, path_list_flag);
@@ -1412,6 +1418,8 @@ bool BLO_write_file(Main *mainvar,
           BLI_assert(0); /* Unreachable. */
           break;
       }
+
+      STRNCPY(mainvar->filepath, mainvar_filepath_orig);
     }
   }



More information about the Bf-blender-cvs mailing list