1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-01-24 07:36:39 +00:00

Use tmp dir during clone to keep orignal passstore in case of error

This commit is contained in:
Quentin Rouland 2025-01-10 14:41:04 +01:00
parent 80a5055b78
commit 3aa99791b8
8 changed files with 45 additions and 18 deletions

View File

@ -1,15 +1,34 @@
#include <QUrl>
#include <QtCore/QDir>
#include <QDebug>
#include <QStandardPaths>
#include "git.h"
#include "libgit.h"
bool Git::clone(QString url, QString path)
bool Git::clone(QString url, QString destination_dir_path)
{
qInfo() << "Cloning " << url << "password_store to " << path;
QDir dir(path);
dir.removeRecursively(); // TODO see if we delete only after sucessfull clone / Will be change anyway when will add update etc..
return LibGit::instance()->clone(url, path);
qInfo() << "Cloning " << url << " to destination " << destination_dir_path;
QDir tmp_dir(QStandardPaths::writableLocation(
QStandardPaths::CacheLocation).append("/clone"));
tmp_dir.removeRecursively();
tmp_dir.mkpath(".");
qDebug() << "Temp dir path is " << tmp_dir.absolutePath();
qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath();
auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling
if(ret) {
qDebug() << "Removing password_store " << destination_dir_path;
QDir destination_dir(destination_dir_path);
destination_dir.removeRecursively();
qDebug() << "Moving cloned content to destination dir";
QDir dir;
qDebug() << tmp_dir.absolutePath() << " to " << destination_dir.absolutePath();
ret = dir.rename(tmp_dir.absolutePath(), destination_dir.absolutePath()); // TODO Better error handling
}
//tmp_dir.removeRecursively();
return ret ;
}

View File

@ -39,7 +39,6 @@ int LibGit::credentials_cb(git_cred **out, const char *url, const char *username
}
bool LibGit::clone(QString url, QString path) {
qDebug("yo");
git_repository *repo = NULL;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
opts.fetch_opts.callbacks.credentials = *credentials_cb;

View File

@ -22,8 +22,6 @@ private:
void initGpgConfig();
public:
~Gpg() = default;
static std::shared_ptr<Gpg> instance()
{
static std::shared_ptr<Gpg> s{new Gpg};

View File

@ -7,12 +7,10 @@
#include "utils.h"
Utils::Utils() {};
bool Utils::unzip(QUrl zip_url, QString dir_out_path)
{
auto tmp_dir_path = QStandardPaths::writableLocation(
QStandardPaths::TempLocation).append("/unzip");
QStandardPaths::CacheLocation).append("/unzip");
QDir tmp_dir(tmp_dir_path);
tmp_dir.removeRecursively();

View File

@ -10,7 +10,7 @@ class Utils : public QObject
Q_OBJECT
public:
Utils();
Utils() = default;
~Utils() override = default;
Q_INVOKABLE bool unzip(QUrl zip_url, QString dir_out);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: utpass.qrouland\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-10 13:55+0100\n"
"POT-Creation-Date: 2025-01-10 14:39+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -133,6 +133,11 @@ msgstr ""
msgid "An error occured during git clone !"
msgstr ""
#: ../qml/pages/settings/ImportGitClone.qml:85
#: ../qml/pages/settings/ImportZip.qml:89
msgid "Password store sucessfully imported !"
msgstr ""
#: ../qml/pages/settings/ImportKeyFile.qml:17
msgid "GPG Key Import"
msgstr ""
@ -158,10 +163,6 @@ msgstr ""
msgid "Password store import failed !"
msgstr ""
#: ../qml/pages/settings/ImportZip.qml:89
msgid "Password store sucessfully imported !"
msgstr ""
#: ../qml/pages/settings/InfoKeys.qml:16
msgid "Info Keys"
msgstr ""

View File

@ -51,7 +51,7 @@ Page {
onClicked: {
var ret = Git.clone(textFieldInput.text, Pass.password_store)
if(ret) {
pageStack.pop()
PopupUtils.open(dialogImportGitCloneSuccess)
} else {
PopupUtils.open(importGitCloneError, importGitClonePage)
}
@ -79,6 +79,17 @@ Page {
}
}
Component {
id: dialogImportGitCloneSuccess
SuccessDialog {
textSuccess: i18n.tr("Password store sucessfully imported !")
onDialogClosed: {
pageStack.pop()
pageStack.pop()
}
}
}
Component.onCompleted: {
PopupUtils.open(importGitCloneValidation, importGitClonePage)
}

View File

@ -89,6 +89,7 @@ Page {
textSuccess: i18n.tr("Password store sucessfully imported !")
onDialogClosed: {
pageStack.pop()
pageStack.pop()
}
}
}