From 8dbd406ea0f495b3d404a7433a32b4781953e55a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Dec 2021 16:17:28 +1100 Subject: 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. --- source/blender/blenloader/intern/writefile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index e0ff70d4b49..aa3eef4b475 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1319,6 +1319,7 @@ bool BLO_write_file(Main *mainvar, ReportList *reports) { BLI_assert(!BLI_path_is_rel(filepath)); + BLI_assert(BLI_path_is_abs_from_cwd(filepath)); char tempname[FILE_MAX + 1]; WriteWrap ww; -- cgit v1.2.3