mirror of
https://github.com/QRouland/UTPass.git
synced 2025-01-24 15:46:40 +00:00
Use tmp dir during clone to keep orignal passstore in case of error
This commit is contained in:
parent
80a5055b78
commit
3aa99791b8
@ -1,15 +1,34 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include "git.h"
|
#include "git.h"
|
||||||
#include "libgit.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;
|
qInfo() << "Cloning " << url << " to destination " << destination_dir_path;
|
||||||
QDir dir(path);
|
QDir tmp_dir(QStandardPaths::writableLocation(
|
||||||
dir.removeRecursively(); // TODO see if we delete only after sucessfull clone / Will be change anyway when will add update etc..
|
QStandardPaths::CacheLocation).append("/clone"));
|
||||||
return LibGit::instance()->clone(url, path);
|
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 ;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ int LibGit::credentials_cb(git_cred **out, const char *url, const char *username
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool LibGit::clone(QString url, QString path) {
|
bool LibGit::clone(QString url, QString path) {
|
||||||
qDebug("yo");
|
|
||||||
git_repository *repo = NULL;
|
git_repository *repo = NULL;
|
||||||
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
|
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
|
||||||
opts.fetch_opts.callbacks.credentials = *credentials_cb;
|
opts.fetch_opts.callbacks.credentials = *credentials_cb;
|
||||||
|
@ -22,8 +22,6 @@ private:
|
|||||||
void initGpgConfig();
|
void initGpgConfig();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~Gpg() = default;
|
|
||||||
|
|
||||||
static std::shared_ptr<Gpg> instance()
|
static std::shared_ptr<Gpg> instance()
|
||||||
{
|
{
|
||||||
static std::shared_ptr<Gpg> s{new Gpg};
|
static std::shared_ptr<Gpg> s{new Gpg};
|
||||||
|
@ -7,12 +7,10 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
Utils::Utils() {};
|
|
||||||
|
|
||||||
bool Utils::unzip(QUrl zip_url, QString dir_out_path)
|
bool Utils::unzip(QUrl zip_url, QString dir_out_path)
|
||||||
{
|
{
|
||||||
auto tmp_dir_path = QStandardPaths::writableLocation(
|
auto tmp_dir_path = QStandardPaths::writableLocation(
|
||||||
QStandardPaths::TempLocation).append("/unzip");
|
QStandardPaths::CacheLocation).append("/unzip");
|
||||||
|
|
||||||
QDir tmp_dir(tmp_dir_path);
|
QDir tmp_dir(tmp_dir_path);
|
||||||
tmp_dir.removeRecursively();
|
tmp_dir.removeRecursively();
|
||||||
|
@ -10,7 +10,7 @@ class Utils : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils();
|
Utils() = default;
|
||||||
~Utils() override = default;
|
~Utils() override = default;
|
||||||
|
|
||||||
Q_INVOKABLE bool unzip(QUrl zip_url, QString dir_out);
|
Q_INVOKABLE bool unzip(QUrl zip_url, QString dir_out);
|
||||||
|
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: utpass.qrouland\n"
|
"Project-Id-Version: utpass.qrouland\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -133,6 +133,11 @@ msgstr ""
|
|||||||
msgid "An error occured during git clone !"
|
msgid "An error occured during git clone !"
|
||||||
msgstr ""
|
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
|
#: ../qml/pages/settings/ImportKeyFile.qml:17
|
||||||
msgid "GPG Key Import"
|
msgid "GPG Key Import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -158,10 +163,6 @@ msgstr ""
|
|||||||
msgid "Password store import failed !"
|
msgid "Password store import failed !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/ImportZip.qml:89
|
|
||||||
msgid "Password store sucessfully imported !"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: ../qml/pages/settings/InfoKeys.qml:16
|
#: ../qml/pages/settings/InfoKeys.qml:16
|
||||||
msgid "Info Keys"
|
msgid "Info Keys"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -51,7 +51,7 @@ Page {
|
|||||||
onClicked: {
|
onClicked: {
|
||||||
var ret = Git.clone(textFieldInput.text, Pass.password_store)
|
var ret = Git.clone(textFieldInput.text, Pass.password_store)
|
||||||
if(ret) {
|
if(ret) {
|
||||||
pageStack.pop()
|
PopupUtils.open(dialogImportGitCloneSuccess)
|
||||||
} else {
|
} else {
|
||||||
PopupUtils.open(importGitCloneError, importGitClonePage)
|
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: {
|
Component.onCompleted: {
|
||||||
PopupUtils.open(importGitCloneValidation, importGitClonePage)
|
PopupUtils.open(importGitCloneValidation, importGitClonePage)
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ Page {
|
|||||||
textSuccess: i18n.tr("Password store sucessfully imported !")
|
textSuccess: i18n.tr("Password store sucessfully imported !")
|
||||||
onDialogClosed: {
|
onDialogClosed: {
|
||||||
pageStack.pop()
|
pageStack.pop()
|
||||||
|
pageStack.pop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user