From 84d766f0ebccea7de519e2d4e59fef5f3004af99 Mon Sep 17 00:00:00 2001 From: flachyjoe Date: Thu, 16 Jun 2022 22:13:43 +0200 Subject: [PATCH] [App] Fix #5592 : Respect symbolic links Use the real path to the file when saving the document. --- src/App/Document.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 00fee2e0d4..049a550a7e 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -2614,23 +2614,28 @@ bool Document::saveToFile(const char* filename) const bool policy = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Document")->GetBool("BackupPolicy",true); + //realpath is canonical filename i.e. without symlink +#ifdef FC_OS_WIN32 + QString utf8Name = QString::fromUtf8(filename); + auto realpath = fs::canonical(fs::path(utf8Name.toStdWString())); +#else + auto realpath = fs::canonical(fs::path(filename)); +#endif + // make a tmp. file where to save the project data first and then rename to // the actual file name. This may be useful if overwriting an existing file // fails so that the data of the work up to now isn't lost. std::string uuid = Base::Uuid::createUuid(); - std::string fn = filename; + std::string fn = realpath.native(); if (policy) { fn += "."; fn += uuid; } Base::FileInfo tmp(fn); + + // In case some folders in the path do not exist -#ifdef FC_OS_WIN32 - QString utf8Name = QString::fromUtf8(filename); - auto parentPath = fs::absolute(fs::path(utf8Name.toStdWString())).parent_path(); -#else - auto parentPath = fs::absolute(fs::path(filename)).parent_path(); -#endif + auto parentPath = realpath.parent_path(); fs::create_directories(parentPath); // open extra scope to close ZipWriter properly @@ -2677,9 +2682,9 @@ bool Document::saveToFile(const char* filename) const count_bak = -1; } bool useFCBakExtension = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Document")->GetBool("UseFCBakExtension",false); - std::string saveBackupDateFormat = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Document")->GetASCII("SaveBackupDateFormat","%Y%m%d-%H%M%S"); + ("User parameter:BaseApp/Preferences/Document")->GetBool("UseFCBakExtension",false); + std::string saveBackupDateFormat = App::GetApplication().GetParameterGroupByPath + ("User parameter:BaseApp/Preferences/Document")->GetASCII("SaveBackupDateFormat","%Y%m%d-%H%M%S"); BackupPolicy policy; if (useFCBakExtension) { @@ -2691,7 +2696,7 @@ bool Document::saveToFile(const char* filename) const policy.setPolicy(BackupPolicy::Standard); } policy.setNumberOfFiles(count_bak); - policy.apply(fn, filename); + policy.apply(fn, realpath.native()); } signalFinishSave(*this, filename);