Skip to content

Commit

Permalink
Adds more explicit error message when auxiliary storage is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere authored and nyalldawson committed Oct 7, 2018
1 parent 119cd8a commit 1ecc57d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
28 changes: 23 additions & 5 deletions src/core/qgsauxiliarystorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,15 +626,33 @@ bool QgsAuxiliaryStorage::duplicateTable( const QgsDataSourceUri &ogrUri, const
return rc;
}

bool QgsAuxiliaryStorage::saveAs( const QString &filename ) const
QString QgsAuxiliaryStorage::errorString() const
{
if ( QFile::exists( filename ) )
QFile::remove( filename );
return mErrorString;
}

bool QgsAuxiliaryStorage::saveAs( const QString &filename )
{
mErrorString.clear();

QFile dest( filename );
if ( dest.exists() && !dest.remove() )
{
mErrorString = dest.errorString();
return false;
}

QFile origin( currentFileName() );
if ( !origin.copy( filename ) )
{
mErrorString = origin.errorString();
return false;
}

return QFile::copy( currentFileName(), filename );
return true;
}

bool QgsAuxiliaryStorage::saveAs( const QgsProject &project ) const
bool QgsAuxiliaryStorage::saveAs( const QgsProject &project )
{
return saveAs( filenameForProject( project ) );
}
Expand Down
7 changes: 5 additions & 2 deletions src/core/qgsauxiliarystorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,14 @@ class CORE_EXPORT QgsAuxiliaryStorage
*/
QString currentFileName() const;

QString errorString() const;

/**
* Saves the current database to a new path.
*
* \returns true if everything is saved, false otherwise
*/
bool saveAs( const QString &filename ) const;
bool saveAs( const QString &filename );

/**
* Saves the current database to a new path for a specific project.
Expand All @@ -333,7 +335,7 @@ class CORE_EXPORT QgsAuxiliaryStorage
*
* \returns true if everything is saved, false otherwise
*/
bool saveAs( const QgsProject &project ) const;
bool saveAs( const QgsProject &project );

/**
* Saves the current database.
Expand Down Expand Up @@ -408,6 +410,7 @@ class CORE_EXPORT QgsAuxiliaryStorage
QString mFileName; // original filename
QString mTmpFileName; // temporary filename used in copy mode
bool mCopy = false;
QString mErrorString;
};

#endif
8 changes: 6 additions & 2 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,10 @@ bool QgsProject::write()

// errors raised during writing project file are more important
if ( !asOk && writeOk )
setError( tr( "Unable to save auxiliary storage" ) );
{
const QString err = mAuxiliaryStorage->errorString();
setError( tr( "Unable to save auxiliary storage ('%1')" ).arg( err ) );
}

return asOk && writeOk;
}
Expand Down Expand Up @@ -2614,7 +2617,8 @@ bool QgsProject::zip( const QString &filename )

if ( ! saveAuxiliaryStorage( asFileName ) )
{
setError( tr( "Unable to save auxiliary storage" ) );
const QString err = mAuxiliaryStorage->errorString();
setError( tr( "Unable to save auxiliary storage ('%1')" ).arg( err ) );
return false;
}

Expand Down

0 comments on commit 1ecc57d

Please sign in to comment.