From 5582b4dd7061220d2786f6ed9f4f658f4d2e864b Mon Sep 17 00:00:00 2001 From: Quentin Rouland Date: Tue, 4 Feb 2025 13:37:25 +0100 Subject: [PATCH] Ensure that key and zip are deleted after import --- plugins/Utils/utils.cpp | 13 ++++++++++++- plugins/Utils/utils.h | 28 +++++++++++++++++++--------- qml/pages/settings/ImportKeyFile.qml | 2 ++ qml/pages/settings/ImportZip.qml | 4 +++- qml/pages/settings/InfoKeys.qml | 5 ++--- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/plugins/Utils/utils.cpp b/plugins/Utils/utils.cpp index dbe8d7b..737998e 100644 --- a/plugins/Utils/utils.cpp +++ b/plugins/Utils/utils.cpp @@ -29,7 +29,7 @@ void Utils::unzipResult(bool err) qDebug() << "Unzip Result"; if (err) { qInfo() << "Unzip Failed"; - emit unzipFailed("failed to unzip archive"); + emit unzipFailed(); } else { qInfo() << "Unzip Succeed"; @@ -45,3 +45,14 @@ QString Utils::manifestPath() qInfo() << "Manifest path : " << path; return path; } + +bool Utils::rmFile(QUrl file_url) +{ + return QFile::remove(file_url.toLocalFile()); +} + +bool Utils::rmDir(QUrl dir_url) +{ + QDir dir(dir_url.toLocalFile()); + return dir.removeRecursively(); +} diff --git a/plugins/Utils/utils.h b/plugins/Utils/utils.h index 7e4dc85..5972449 100644 --- a/plugins/Utils/utils.h +++ b/plugins/Utils/utils.h @@ -34,9 +34,8 @@ signals: /** * @brief Emitted when the unzipping operation fails. - * @param message The error message describing the failure. */ - void unzipFailed(QString message); + void unzipFailed(); private: std::unique_ptr m_sem; /**< Semaphore for managing concurrent operations. */ @@ -48,19 +47,14 @@ public: Utils(); /** - * @brief Unzips a ZIP file to the specified output directory. - * - * This method extracts the contents of a ZIP file from the specified URL and saves them to the provided - * output directory path. + * @brief Start a job to unzips a ZIP file to the specified output directory. * * @param zip_url The URL of the ZIP file to unzip. * @param dir_out The output directory where the contents of the ZIP file should be extracted. - * @return `true` if the unzipping operation was successful, `false` otherwise. + * @return `true` if the unzipping job is started successfullly, `false` otherwise. */ Q_INVOKABLE bool unzip(QUrl zip_url, QString dir_out); - - /** * @brief Retrieves the path to the manifest data. * @@ -70,6 +64,22 @@ public: */ Q_INVOKABLE QString manifestPath(); + /** + * @brief Removes a file located at the specified URL. + * + * @param file_url The URL of the file to remove. + * @return `true` if the file was successfully removed; `false` otherwise. + */ + Q_INVOKABLE bool rmFile(QUrl file_url); + + /** + * @brief Removes a directory located at the specified URL. + * + * @param dir_url The URL of the directory to remove. + * @return `true` if the directory was successfully removed; `false` otherwise. + */ + Q_INVOKABLE bool rmDir(QUrl dir_url); + }; #endif diff --git a/qml/pages/settings/ImportKeyFile.qml b/qml/pages/settings/ImportKeyFile.qml index d4d8b7b..afd0471 100644 --- a/qml/pages/settings/ImportKeyFile.qml +++ b/qml/pages/settings/ImportKeyFile.qml @@ -31,10 +31,12 @@ Page { var status = Pass.importGPGKey(importKeyFilePage.activeTransfer.items[0].url); Pass.importGPGKeySucceed.connect(function() { importKeyFilePage.activeTransfer = null; + Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url); PopupUtils.open(dialogImportKeyPageSucess); }); Pass.importGPGKeyFailed.connect(function(message) { importKeyFilePage.activeTransfer = null; + Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url); PopupUtils.open(dialogImportKeyPageError); }); } diff --git a/qml/pages/settings/ImportZip.qml b/qml/pages/settings/ImportZip.qml index 7de1b90..6585211 100644 --- a/qml/pages/settings/ImportZip.qml +++ b/qml/pages/settings/ImportZip.qml @@ -35,10 +35,12 @@ Page { var status = Utils.unzip(importZipPage.activeTransfer.items[0].url, Pass.getPasswordStore()); Utils.unzipSucceed.connect(function() { importZipPage.activeTransfer = null; + Utils.rmFile(importZipPage.activeTransfer.items[0].url); PopupUtils.open(dialogImportZipPageSuccess); }); - Utils.unzipFailed.connect(function(message) { + Utils.unzipFailed.connect(function() { importZipPage.activeTransfer = null; + Utils.rmFile(importZipPage.activeTransfer.items[0].url); PopupUtils.open(dialogImportZipPageError); }); } diff --git a/qml/pages/settings/InfoKeys.qml b/qml/pages/settings/InfoKeys.qml index 02ebf6d..f9c51ba 100644 --- a/qml/pages/settings/InfoKeys.qml +++ b/qml/pages/settings/InfoKeys.qml @@ -89,11 +89,10 @@ Page { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: { - if (!model.modelData) { + if (!model.modelData) ""; - } else { + else model.modelData.keyid; - } } color: theme.palette.normal.backgroundText }