[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.
This commit is contained in:
Ajinkya Dahale
2021-09-19 14:07:27 -04:00
committed by wwmayer
parent 3dd5438880
commit b7ea205c70

View File

@@ -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
{