+ fixes #0001237: the project file is not saved when the /tmp directory is full, but the user is not aware of it

This commit is contained in:
wmayer 2015-09-19 18:59:22 +02:00
parent bd1fc886fe
commit 7d09444dd9
6 changed files with 90 additions and 20 deletions

View File

@ -1075,6 +1075,10 @@ bool Document::save (void)
// write additional files
writer.writeFiles();
if (writer.hasErrors()) {
throw Base::FileException("Failed to write all data to file", tmp);
}
GetApplication().signalSaveDocument(*this);
}

View File

@ -52,11 +52,22 @@ std::string DocumentPy::representation(void) const
PyObject* DocumentPy::save(PyObject * args)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception
if (!getDocumentPtr()->save()) {
PyErr_Format(PyExc_ValueError, "Object attribute 'FileName' is not set");
return NULL;
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception
try {
if (!getDocumentPtr()->save()) {
PyErr_SetString(PyExc_ValueError, "Object attribute 'FileName' is not set");
return NULL;
}
}
catch (const Base::FileException& e) {
PyErr_SetString(PyExc_IOError, e.what());
return 0;
}
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
const char* filename = getDocumentPtr()->FileName.getValue();
@ -72,11 +83,22 @@ PyObject* DocumentPy::save(PyObject * args)
PyObject* DocumentPy::saveAs(PyObject * args)
{
char* fn;
if (!PyArg_ParseTuple(args, "s", &fn)) // convert args: Python->C
return NULL; // NULL triggers exception
if (!getDocumentPtr()->saveAs(fn)) {
PyErr_Format(PyExc_ValueError, "Object attribute 'FileName' is not set");
return NULL;
if (!PyArg_ParseTuple(args, "s", &fn)) // convert args: Python->C
return NULL; // NULL triggers exception
try {
if (!getDocumentPtr()->saveAs(fn)) {
PyErr_SetString(PyExc_ValueError, "Object attribute 'FileName' is not set");
return NULL;
}
}
catch (const Base::FileException& e) {
PyErr_SetString(PyExc_IOError, e.what());
return 0;
}
catch (const Base::Exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
return 0;
}
Base::FileInfo fi(fn);

View File

@ -141,6 +141,26 @@ void Writer::clearModes()
Modes.clear();
}
void Writer::addError(const std::string& msg)
{
Errors.push_back(msg);
}
bool Writer::hasErrors() const
{
return (!Errors.empty());
}
void Writer::clearErrors()
{
Errors.clear();
}
std::vector<std::string> Writer::getErrors() const
{
return Errors;
}
std::string Writer::addFile(const char* Name,const Base::Persistence *Object)
{
// always check isForceXML() before requesting a file!

View File

@ -95,6 +95,14 @@ public:
void clearModes();
//@}
/** @name Error handling */
//@{
void addError(const std::string&);
bool hasErrors() const;
void clearErrors();
std::vector<std::string> getErrors() const;
//@}
/** @name pretty formating for XML */
//@{
/// get the current indentation
@ -118,6 +126,7 @@ protected:
};
std::vector<FileEntry> FileList;
std::vector<std::string> FileNames;
std::vector<std::string> Errors;
std::set<std::string> Modes;
short indent;

View File

@ -605,10 +605,16 @@ App::Document* Document::getDocument(void) const
bool Document::save(void)
{
if (d->_pcDocument->isSaved()) {
Gui::WaitCursor wc;
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").save()"
,d->_pcDocument->getName());
setModified(false);
try {
Gui::WaitCursor wc;
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").save()"
,d->_pcDocument->getName());
setModified(false);
}
catch (const Base::Exception& e) {
QMessageBox::critical(getMainWindow(), QObject::tr("Saving document failed"),
QString::fromLatin1(e.what()));
}
return true;
}
else {
@ -631,12 +637,17 @@ bool Document::saveAs(void)
const char * DocName = App::GetApplication().getDocumentName(getDocument());
// save as new file name
Gui::WaitCursor wc;
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs(\"%s\")"
, DocName, (const char*)fn.toUtf8());
setModified(false);
getMainWindow()->appendRecentFile(fi.filePath());
try {
Gui::WaitCursor wc;
Command::doCommand(Command::Doc,"App.getDocument(\"%s\").saveAs(\"%s\")"
, DocName, (const char*)fn.toUtf8());
setModified(false);
getMainWindow()->appendRecentFile(fi.filePath());
}
catch (const Base::Exception& e) {
QMessageBox::critical(getMainWindow(), QObject::tr("Saving document failed"),
QString::fromLatin1(e.what()));
}
return true;
}
else {

View File

@ -294,6 +294,10 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const
else {
Base::Console().Error("Cannot save BRep file '%s'\n", fi.filePath().c_str());
}
std::stringstream ss;
ss << "Cannot save BRep file '" << fi.filePath() << "'";
writer.addError(ss.str());
}
Base::ifstream file(fi, std::ios::in | std::ios::binary);