1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-07-02 10:12:28 +00:00

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

This commit is contained in:
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);