From 1d8574e436f795bcfe64e17f0febd9743c1c7fa5 Mon Sep 17 00:00:00 2001 From: Blottiere Paul Date: Thu, 13 Jul 2017 14:55:02 +0100 Subject: [PATCH] Temporary .qgs files are deleted --- python/core/qgsarchive.sip | 7 +++++++ src/core/qgsarchive.cpp | 14 ++++++++++++++ src/core/qgsarchive.h | 6 ++++++ src/core/qgsproject.cpp | 8 +++----- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/python/core/qgsarchive.sip b/python/core/qgsarchive.sip index 7bdd00388d7..5336df281b4 100644 --- a/python/core/qgsarchive.sip +++ b/python/core/qgsarchive.sip @@ -136,6 +136,13 @@ class QgsProjectArchive : QgsArchive Returns the current .qgs project file or an empty string if there's none :rtype: str %End + + bool clearProjectFile(); +%Docstring + Remove the current .qgs project file from the temporary directory. + :return: true if the file is well removed, false otherwise + :rtype: bool +%End }; /************************************************************************ diff --git a/src/core/qgsarchive.cpp b/src/core/qgsarchive.cpp index 278b54eb4a9..2658f2ab0e8 100644 --- a/src/core/qgsarchive.cpp +++ b/src/core/qgsarchive.cpp @@ -152,3 +152,17 @@ bool QgsProjectArchive::unzip( const QString &filename ) else return false; } + +bool QgsProjectArchive::clearProjectFile() +{ + bool rc = false; + QString file = projectFile(); + + if ( !file.isEmpty() && QFile::exists( file ) ) + rc = QFile::remove( file ); + + if ( rc ) + mFiles.removeOne( file ); + + return rc; +} diff --git a/src/core/qgsarchive.h b/src/core/qgsarchive.h index c1c7ce911d1..c6aed2abccf 100644 --- a/src/core/qgsarchive.h +++ b/src/core/qgsarchive.h @@ -147,6 +147,12 @@ class CORE_EXPORT QgsProjectArchive : public QgsArchive * Returns the current .qgs project file or an empty string if there's none */ QString projectFile() const; + + /** + * Remove the current .qgs project file from the temporary directory. + * \returns true if the file is well removed, false otherwise + */ + bool clearProjectFile(); }; #endif diff --git a/src/core/qgsproject.cpp b/src/core/qgsproject.cpp index aa066ec6934..c22f1dbfae5 100644 --- a/src/core/qgsproject.cpp +++ b/src/core/qgsproject.cpp @@ -2110,17 +2110,18 @@ bool QgsProject::unzip( const QString &filename ) return false; } - // keep the archive + // keep the archive and remove the temporary .qgs file mUnzipping = false; mPathResolverBaseName = QString(); mArchive.reset( archive.release() ); + mArchive->clearProjectFile(); return true; } bool QgsProject::zip() { - if ( unzipped() ) + if ( !mArchive->filename().isEmpty() ) return zip( mArchive->filename() ); return false; @@ -2168,9 +2169,6 @@ bool QgsProject::zip( const QString &filename ) return false; } - // keep the archive - mArchive.reset( archive.release() ); - return true; }