mirror of
https://github.com/QRouland/UTPass.git
synced 2025-06-24 22:42:28 +00:00
Use tmp dir during clone to keep orignal passstore in case of error
This commit is contained in:
@ -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 ;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user