Skip to content

Commit

Permalink
+ fixes #1237: the project file is not saved when the /tmp directory …
Browse files Browse the repository at this point in the history
…is full, but the user is not aware of it
  • Loading branch information
wwmayer committed Sep 19, 2015
1 parent bd1fc88 commit 7d09444
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/App/Document.cpp
Expand Up @@ -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);
}

Expand Down
42 changes: 32 additions & 10 deletions src/App/DocumentPyImp.cpp
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/Base/Writer.cpp
Expand Up @@ -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!
Expand Down
9 changes: 9 additions & 0 deletions src/Base/Writer.h
Expand Up @@ -95,6 +95,14 @@ class BaseExport Writer
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
Expand All @@ -118,6 +126,7 @@ class BaseExport Writer
};
std::vector<FileEntry> FileList;
std::vector<std::string> FileNames;
std::vector<std::string> Errors;
std::set<std::string> Modes;

short indent;
Expand Down
31 changes: 21 additions & 10 deletions src/Gui/Document.cpp
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Part/App/PropertyTopoShape.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 7d09444

Please sign in to comment.