From 92b3a5430a0d925337f4f1e448e1dd2c5b29e1bf Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Sun, 19 Sep 2021 14:07:27 -0400 Subject: [PATCH] [App] Fix regression introduced by PR #4996 Files opened by running `freecad xxxx.FCStd` or similar relative paths could not be saved because of new code introduced to create parent directories. See https://github.com/FreeCAD/FreeCAD/pull/4996#issuecomment-922370077 and https://forum.freecadweb.org/viewtopic.php?f=13&t=62319&p=534156#p534156. This commit resolves the issue by ensuring the parent path is absolute while saving. We would probably like to make sure the file name is itself stored with absolute path, but there's a few problems 1. There may be other occurences where files are loaded with relative paths. So having a check here is a good idea. 2. Files opened by `freecad xxxx.FCStd` somehow don't have the issue where renaming parent directory throws an exception on save. Instead the file is saved in the new location. --- src/App/Document.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index a30293128e..30f3b69f68 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2613,9 +2613,8 @@ bool Document::saveToFile(const char* filename) const } Base::FileInfo tmp(fn); // In case some folders in the path do not exist - fs::path parent = fs::path(filename).parent_path(); - if (!parent.empty() && !parent.filename_is_dot() && !parent.filename_is_dot_dot()) - fs::create_directories(parent); + auto parentPath = fs::absolute(fs::path(filename)).parent_path(); + fs::create_directories(parentPath); // open extra scope to close ZipWriter properly {