[Core] (Partially?) Fix data loss on dir rename (#4996)

* Fix lost filename in err msg

In some circumstances, FileExceptions are constructed empty, then have a
filename assigned to them, but the error message in these scenarios is
left as the default "unknown" one, which is sometimes shown to users.
This change fixes that case to be consistent with instances that are
constructed with the filename.

The exception can happen when trying to save the file in a location that does
not exist, or when the user does not have permission to write there. If it
comes when saving after closing the document, all previous changes can be lost.

Partially fixes issue #4098.

Co-authored-by: Heewa Barfchin <heewa.b@gmail.com>
This commit is contained in:
Ajinkya Dahale
2021-09-16 13:06:29 -04:00
committed by GitHub
parent 5694f08f15
commit c123bc2bf8
4 changed files with 104 additions and 14 deletions

View File

@@ -66,6 +66,7 @@ recompute path. Also, it enables more complicated dependencies beyond trees.
# include <climits>
# include <bitset>
# include <random>
# include <boost/filesystem.hpp>
#endif
#include <boost/algorithm/string.hpp>
@@ -142,6 +143,8 @@ using namespace zipios;
# define FC_LOGFEATUREUPDATE
#endif
namespace fs = boost::filesystem;
// typedef boost::property<boost::vertex_root_t, DocumentObject* > VertexProperty;
typedef boost::adjacency_list <
boost::vecS, // class OutEdgeListS : a Sequence or an AssociativeContainer
@@ -2610,6 +2613,8 @@ bool Document::saveToFile(const char* filename) const
fn += uuid;
}
Base::FileInfo tmp(fn);
// In case some folders in the path do not exist
fs::create_directories(fs::path(filename).parent_path());
// open extra scope to close ZipWriter properly
{