Fix T62612: Saving with "Remap Relative" makes ALL paths relative

This commit is contained in:
2020-02-18 22:03:07 +11:00
parent d4e38d99b2
commit f7386b9757
4 changed files with 101 additions and 25 deletions

View File

@@ -4056,41 +4056,38 @@ bool BLO_write_file(Main *mainvar,
return 0;
}
/* check if we need to backup and restore paths */
if (UNLIKELY((write_flags & G_FILE_RELATIVE_REMAP) && (G_FILE_SAVE_COPY & write_flags))) {
path_list_backup = BKE_bpath_list_backup(mainvar, path_list_flag);
}
/* remapping of relative paths to new file location */
/* Remapping of relative paths to new file location. */
if (write_flags & G_FILE_RELATIVE_REMAP) {
char dir1[FILE_MAX];
char dir2[FILE_MAX];
BLI_split_dir_part(filepath, dir1, sizeof(dir1));
BLI_split_dir_part(mainvar->name, dir2, sizeof(dir2));
char dir_src[FILE_MAX];
char dir_dst[FILE_MAX];
BLI_split_dir_part(mainvar->name, dir_src, sizeof(dir_src));
BLI_split_dir_part(filepath, dir_dst, sizeof(dir_dst));
/* just in case there is some subtle difference */
BLI_cleanup_dir(mainvar->name, dir1);
BLI_cleanup_dir(mainvar->name, dir2);
BLI_cleanup_dir(mainvar->name, dir_dst);
BLI_cleanup_dir(mainvar->name, dir_src);
if (G.relbase_valid && (BLI_path_cmp(dir1, dir2) == 0)) {
if (G.relbase_valid && (BLI_path_cmp(dir_dst, dir_src) == 0)) {
/* Saved to same path. Nothing to do. */
write_flags &= ~G_FILE_RELATIVE_REMAP;
}
else {
/* Check if we need to backup and restore paths. */
if (UNLIKELY(G_FILE_SAVE_COPY & write_flags)) {
path_list_backup = BKE_bpath_list_backup(mainvar, path_list_flag);
}
if (G.relbase_valid) {
/* blend may not have been saved before. Tn this case
* we should not have any relative paths, but if there
* is somehow, an invalid or empty G_MAIN->name it will
* print an error, don't try make the absolute in this case. */
BKE_bpath_absolute_convert(mainvar, BKE_main_blendfile_path_from_global(), NULL);
/* Saved, make relative paths relative to new location (if possible). */
BKE_bpath_relative_rebase(mainvar, dir_src, dir_dst, NULL);
}
else {
/* Unsaved, make all relative. */
BKE_bpath_relative_convert(mainvar, dir_dst, NULL);
}
}
}
if (write_flags & G_FILE_RELATIVE_REMAP) {
/* note, making relative to something OTHER then G_MAIN->name */
BKE_bpath_relative_convert(mainvar, filepath, NULL);
}
/* actual file writing */
const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, thumb);