Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-12-16 08:17:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-12-16 08:27:35 +0300
commit8dbd406ea0f495b3d404a7433a32b4781953e55a (patch)
treec8056b188efa299986b7d936e0b578e9f1f43232 /source/blender/windowmanager
parent15c36170092d26b7d6106924270b6e590627fcb6 (diff)
WM: various changes to file writing behavior
Saving with only a filename (from Python) wasn't being prevented, while it would successfully write the file to the working-directory, path remapping and setting relative paths wouldn't work afterwards as `Main.filepath` would have no directory component. Disallow this since it's a corner case which only ever occurs when path names without any directories are used from Python, the overhead of expanding the working-directory for all data saving operations isn't worthwhile. The following changes have been made: - bpy.ops.wm.save_mainfile() without a filepath argument fails & reports and error when the file hasn't been saved. Previously it would write to "untitled.blend" and set the `G.main->filepath` to this as well. - bpy.ops.wm.save_mainfile(filepath="untitled.blend") fails & reports and error as the filename has no directory component. - `BLI_path_is_abs_from_cwd` was added to check if the path would attempt to expand to the CWD.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/intern/wm_files.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 7ac9395e16c..1d3fa158ac1 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -3067,12 +3067,32 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
BLO_WRITE_PATH_REMAP_NONE;
save_set_compress(op);
- if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ const bool is_filepath_set = RNA_struct_property_is_set(op->ptr, "filepath");
+ if (is_filepath_set) {
RNA_string_get(op->ptr, "filepath", path);
}
else {
- BLI_strncpy(path, BKE_main_blendfile_path(bmain), FILE_MAX);
- wm_filepath_default(bmain, path);
+ STRNCPY(path, BKE_main_blendfile_path(bmain));
+ }
+
+ if (path[0] == '\0') {
+ BKE_report(op->reports,
+ RPT_ERROR,
+ "Unable to save an unsaved file with an empty or unset \"filepath\" property");
+ return OPERATOR_CANCELLED;
+ }
+
+ /* NOTE(@campbellbarton): only check this for file-path properties so saving an already
+ * saved file never fails with an error.
+ * Even though this should never happen, there may be some corner case where a malformed
+ * path is stored in `G.main->filepath`: when the file path is initialized from recovering
+ * a blend file - for example, so in this case failing to save isn't ideal. */
+ if (is_filepath_set && !BLI_path_is_abs_from_cwd(path)) {
+ BKE_reportf(op->reports,
+ RPT_ERROR,
+ "The \"filepath\" property was not an absolute path: \"%s\"",
+ path);
+ return OPERATOR_CANCELLED;
}
const int fileflags_orig = G.fileflags;