1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 06:57:15 +00:00

Ensure that key and zip are deleted after import

This commit is contained in:
Quentin Rouland 2025-02-04 13:37:25 +01:00
parent ba52ddac5c
commit 5582b4dd70
5 changed files with 38 additions and 14 deletions

View File

@ -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();
}

View File

@ -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<QSemaphore> 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

View File

@ -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);
});
}

View File

@ -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);
});
}

View File

@ -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
}