Skip to content

Commit 1ecc57d

Browse files
pblottierenyalldawson
authored andcommittedOct 7, 2018
Adds more explicit error message when auxiliary storage is saved
1 parent 119cd8a commit 1ecc57d

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed
 

‎src/core/qgsauxiliarystorage.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,33 @@ bool QgsAuxiliaryStorage::duplicateTable( const QgsDataSourceUri &ogrUri, const
626626
return rc;
627627
}
628628

629-
bool QgsAuxiliaryStorage::saveAs( const QString &filename ) const
629+
QString QgsAuxiliaryStorage::errorString() const
630630
{
631-
if ( QFile::exists( filename ) )
632-
QFile::remove( filename );
631+
return mErrorString;
632+
}
633+
634+
bool QgsAuxiliaryStorage::saveAs( const QString &filename )
635+
{
636+
mErrorString.clear();
637+
638+
QFile dest( filename );
639+
if ( dest.exists() && !dest.remove() )
640+
{
641+
mErrorString = dest.errorString();
642+
return false;
643+
}
644+
645+
QFile origin( currentFileName() );
646+
if ( !origin.copy( filename ) )
647+
{
648+
mErrorString = origin.errorString();
649+
return false;
650+
}
633651

634-
return QFile::copy( currentFileName(), filename );
652+
return true;
635653
}
636654

637-
bool QgsAuxiliaryStorage::saveAs( const QgsProject &project ) const
655+
bool QgsAuxiliaryStorage::saveAs( const QgsProject &project )
638656
{
639657
return saveAs( filenameForProject( project ) );
640658
}

‎src/core/qgsauxiliarystorage.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,14 @@ class CORE_EXPORT QgsAuxiliaryStorage
319319
*/
320320
QString currentFileName() const;
321321

322+
QString errorString() const;
323+
322324
/**
323325
* Saves the current database to a new path.
324326
*
325327
* \returns true if everything is saved, false otherwise
326328
*/
327-
bool saveAs( const QString &filename ) const;
329+
bool saveAs( const QString &filename );
328330

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

338340
/**
339341
* Saves the current database.
@@ -408,6 +410,7 @@ class CORE_EXPORT QgsAuxiliaryStorage
408410
QString mFileName; // original filename
409411
QString mTmpFileName; // temporary filename used in copy mode
410412
bool mCopy = false;
413+
QString mErrorString;
411414
};
412415

413416
#endif

‎src/core/qgsproject.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,10 @@ bool QgsProject::write()
16491649

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

16541657
return asOk && writeOk;
16551658
}
@@ -2614,7 +2617,8 @@ bool QgsProject::zip( const QString &filename )
26142617

26152618
if ( ! saveAuxiliaryStorage( asFileName ) )
26162619
{
2617-
setError( tr( "Unable to save auxiliary storage" ) );
2620+
const QString err = mAuxiliaryStorage->errorString();
2621+
setError( tr( "Unable to save auxiliary storage ('%1')" ).arg( err ) );
26182622
return false;
26192623
}
26202624

0 commit comments

Comments
 (0)
Please sign in to comment.