Fix #112423: Recover Autosave breaks library paths.

Trying to 'recover' a normal (non-auto-saved) blendfile would break any
relative paths.

Caused by 88b24bc6bb, it looks like this commit did not take into
account readfile side of the code?

Pull Request: https://projects.blender.org/blender/blender/pulls/115048
This commit is contained in:
Bastien Montagne
2024-01-24 10:49:24 +01:00
parent 6414ca6510
commit 3c62917213
4 changed files with 28 additions and 19 deletions

View File

@@ -900,7 +900,8 @@ static void setup_app_data(bContext *C,
bmain->filepath[0] = '\0';
}
else if (recover) {
/* In case of auto-save or quit.blend, use original filepath instead. */
/* In case of auto-save or quit.blend, use original filepath instead (see also #read_global in
* `readfile.cc`). */
bmain->recovered = true;
STRNCPY(bmain->filepath, bfd->filepath);
}

View File

@@ -57,6 +57,11 @@ typedef struct BlendFileData {
int fileflags;
int globalf;
/** Typically the actual filepath of the read blendfile, except when recovering
* save-on-exit/autosave files. In the latter case, it will be the path of the file that
* generated the auto-saved one being recovered.
*
* NOTE: Currently expected to be the same path as #BlendFileData.filepath. */
char filepath[1024]; /* 1024 = FILE_MAX */
/** TODO: think this isn't needed anymore? */

View File

@@ -3109,25 +3109,21 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
bfd->fileflags = fg->fileflags;
bfd->globalf = fg->globalf;
STRNCPY(bfd->filepath, fg->filepath);
/* Error in 2.65 and older: `main->filepath` was not set if you save from startup
* (not after loading file). */
if (bfd->filepath[0] == 0) {
if (fd->fileversion < 265 || (fd->fileversion == 265 && fg->subversion < 1)) {
if ((G.fileflags & G_FILE_RECOVER_READ) == 0) {
STRNCPY(bfd->filepath, BKE_main_blendfile_path(bfd->main));
}
}
/* early 2.50 version patch - filepath not in FileGlobal struct at all */
if (fd->fileversion <= 250) {
STRNCPY(bfd->filepath, BKE_main_blendfile_path(bfd->main));
}
}
/* Note: since 88b24bc6bb, `fg->filepath` is only written for crash recovery and autosave files,
* so only overwrite `fd->relabase` if it is not empty, in case a regular blendfile is opened
* through one of the 'recover' operators.
*
* In all other cases, the path is just set to the current path of the blendfile being read, so
* there is no need to handle anymore older files (pre-2.65) that did not store (correctly) their
* path. */
if (G.fileflags & G_FILE_RECOVER_READ) {
STRNCPY(fd->relabase, fg->filepath);
if (fg->filepath[0] != '\0') {
STRNCPY(fd->relabase, fg->filepath);
/* Used to set expected original filepath in read Main, instead of the path of the recovery
* file itself. */
STRNCPY(bfd->filepath, fg->filepath);
}
}
bfd->curscreen = fg->curscreen;
@@ -3589,6 +3585,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
bfd->main = BKE_main_new();
bfd->main->versionfile = fd->fileversion;
STRNCPY(bfd->filepath, filepath);
bfd->type = BLENFILETYPE_BLEND;

View File

@@ -65,7 +65,13 @@ struct FileData {
* to detect unchanged data from memfile. */
int undo_direction; /* eUndoStepDir */
/** Now only in use for library appending. */
/** Used for relative paths handling.
*
* Typically the actual filepath of the read blendfile, except when recovering
* save-on-exit/autosave files. In the latter case, it will be the path of the file that
* generated the auto-saved one being recovered.
*
* NOTE: Currently expected to be the same path as #BlendFileData.filepath. */
char relabase[FILE_MAX];
/** General reading variables. */