diff --git a/plugins/Git/git.cpp b/plugins/Git/git.cpp index 2f5ae5e..f1ea083 100644 --- a/plugins/Git/git.cpp +++ b/plugins/Git/git.cpp @@ -1,15 +1,34 @@ #include #include #include +#include #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 ; } diff --git a/plugins/Git/libgit.cpp b/plugins/Git/libgit.cpp index 5f873ad..95f6354 100644 --- a/plugins/Git/libgit.cpp +++ b/plugins/Git/libgit.cpp @@ -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; diff --git a/plugins/Pass/gpg.h b/plugins/Pass/gpg.h index 9c5e381..7b24eee 100644 --- a/plugins/Pass/gpg.h +++ b/plugins/Pass/gpg.h @@ -22,8 +22,6 @@ private: void initGpgConfig(); public: - ~Gpg() = default; - static std::shared_ptr instance() { static std::shared_ptr s{new Gpg}; diff --git a/plugins/Utils/utils.cpp b/plugins/Utils/utils.cpp index f11c767..48acf26 100644 --- a/plugins/Utils/utils.cpp +++ b/plugins/Utils/utils.cpp @@ -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(); diff --git a/plugins/Utils/utils.h b/plugins/Utils/utils.h index 1758f97..bebbe03 100644 --- a/plugins/Utils/utils.h +++ b/plugins/Utils/utils.h @@ -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); diff --git a/po/utpass.qrouland.pot b/po/utpass.qrouland.pot index eba613f..d2a22db 100644 --- a/po/utpass.qrouland.pot +++ b/po/utpass.qrouland.pot @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/qml/pages/settings/ImportGitClone.qml b/qml/pages/settings/ImportGitClone.qml index b589675..a0bcdd8 100644 --- a/qml/pages/settings/ImportGitClone.qml +++ b/qml/pages/settings/ImportGitClone.qml @@ -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) } diff --git a/qml/pages/settings/ImportZip.qml b/qml/pages/settings/ImportZip.qml index 19a64d5..812406f 100644 --- a/qml/pages/settings/ImportZip.qml +++ b/qml/pages/settings/ImportZip.qml @@ -89,6 +89,7 @@ Page { textSuccess: i18n.tr("Password store sucessfully imported !") onDialogClosed: { pageStack.pop() + pageStack.pop() } } }