Skip to content

Commit

Permalink
Merge pull request #270 from tezeb/master
Browse files Browse the repository at this point in the history
Process specific signals for process management
  • Loading branch information
annejan authored Jan 9, 2017
2 parents fe57825 + c23dba7 commit 696e797
Show file tree
Hide file tree
Showing 15 changed files with 319 additions and 329 deletions.
3 changes: 3 additions & 0 deletions qtpass.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ INSTALLS += target
DISTFILES += \
settingsToDelete.txt

RESOURCES += \
src/resources.qrc

1 change: 1 addition & 0 deletions src/configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "mainwindow.h"
#include "qtpasssettings.h"
#include "ui_configdialog.h"
#include "debughelper.h"
#include <QDir>
#include <QMessageBox>
#ifdef Q_OS_WIN
Expand Down
4 changes: 1 addition & 3 deletions src/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ int Executor::executeBlocking(QString app, const QStringList &args,
QString input, QString *process_out,
QString *process_err) {
QProcess internal;
emit starting();
internal.start(app, args);
if (!input.isEmpty()) {
QByteArray data = input.toUtf8();
Expand All @@ -144,7 +143,6 @@ int Executor::executeBlocking(QString app, const QStringList &args,
*process_out = pout;
if (process_err != Q_NULLPTR)
*process_err = perr;
emit finished(internal.exitCode(), pout, perr);
return internal.exitCode();
} else {
// TODO(bezet): emit error() ?
Expand Down Expand Up @@ -192,7 +190,7 @@ void Executor::finished(int exitCode, QProcess::ExitStatus exitStatus) {
if (exitCode != 0)
dbg() << exitCode << err;
}
emit finished(exitCode, output, err);
emit finished(i.id, exitCode, output, err);
}
// else: emit crashed with ID, which may give a chance to recover ?
executeNext();
Expand Down
3 changes: 2 additions & 1 deletion src/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ private slots:
* @param errout stderr produced by the process, if requested or if
* process failed
*/
void finished(int exitCode, const QString &output, const QString &errout);
void finished(int id, int exitCode, const QString &output,
const QString &errout);
void starting();
void error(int id, int exitCode, const QString &output,
const QString &errout);
Expand Down
158 changes: 70 additions & 88 deletions src/imitatepass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
ImitatePass::ImitatePass() {}


/**
* @brief ImitatePass::GitInit git init wrapper
*/
Expand All @@ -20,9 +19,7 @@ void ImitatePass::GitInit() {
/**
* @brief ImitatePass::GitPull git init wrapper
*/
void ImitatePass::GitPull() {
executeGit(GIT_PULL,{"pull"});
}
void ImitatePass::GitPull() { executeGit(GIT_PULL, {"pull"}); }

/**
* @brief ImitatePass::GitPull_b git pull wrapper
Expand All @@ -35,8 +32,8 @@ void ImitatePass::GitPull_b() {
* @brief ImitatePass::GitPush git init wrapper
*/
void ImitatePass::GitPush() {
if(QtPassSettings::isUseGit()){
executeGit(GIT_PUSH, {"push"});
if (QtPassSettings::isUseGit()) {
executeGit(GIT_PUSH, {"push"});
}
}

Expand All @@ -51,18 +48,6 @@ void ImitatePass::Show(QString file) {
executeGpg(PASS_SHOW, args);
}

/**
* @brief ImitatePass::Show_b show content of file, blocking version
*
* @returns process exitCode
*/
int ImitatePass::Show_b(QString file) {
file = QtPassSettings::getPassStore() + file + ".gpg";
QStringList args = {"-d", "--quiet", "--yes", "--no-encrypt-to",
"--batch", "--use-agent", file};
return exec.executeBlocking(QtPassSettings::getGpgExecutable(), args);
}

/**
* @brief ImitatePass::Insert create new file with encrypted content
*
Expand All @@ -88,9 +73,9 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) {
if (overwrite)
args.append("--yes");
args.append("-");
executeGpg(PASS_INSERT, args,
newValue);
executeGpg(PASS_INSERT, args, newValue);
if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) {
// TODO(bezet) why not?
if (!overwrite)
executeGit(GIT_ADD, {"add", file});
QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(file);
Expand Down Expand Up @@ -261,19 +246,16 @@ void ImitatePass::reencryptPath(QString dir) {
// dbg()<< actualKeys << gpgId << getRecipientList(fileName);
dbg() << "reencrypt " << fileName << " for " << gpgId;
QString local_lastDecrypt = "Could not decrypt";
emit lastDecrypt(local_lastDecrypt);
args = QStringList{"-d", "--quiet", "--yes", "--no-encrypt-to",
"--batch", "--use-agent", fileName};
exec.executeBlocking(QtPassSettings::getGpgExecutable(), args,
&local_lastDecrypt);
emit lastDecrypt(local_lastDecrypt);

if (!local_lastDecrypt.isEmpty() &&
local_lastDecrypt != "Could not decrypt") {
if (local_lastDecrypt.right(1) != "\n")
local_lastDecrypt += "\n";

emit lastDecrypt(local_lastDecrypt);
QStringList recipients = Pass::getRecipientList(fileName);
if (recipients.isEmpty()) {
emit critical(tr("Can not edit"),
Expand Down Expand Up @@ -313,78 +295,78 @@ void ImitatePass::reencryptPath(QString dir) {
emit endReencryptPath();
}

void ImitatePass::Move(const QString src, const QString dest, const bool force)
{
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "mv";
if(force){
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_MOVE, args);
void ImitatePass::Move(const QString src, const QString dest,
const bool force) {
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "mv";
if (force) {
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_MOVE, args);

QString message=QString("moved from %1 to %2 using QTPass.");
message= message.arg(src).arg(dest);
GitCommit("", message);
if(QtPassSettings::isAutoPush()){
GitPush();
}
QString message = QString("moved from %1 to %2 using QTPass.");
message = message.arg(src).arg(dest);
GitCommit("", message);
if (QtPassSettings::isAutoPush()) {
GitPush();
}

} else {
QDir qDir;
QFileInfo srcFileInfo(src);
QString destCopy = dest;
if(srcFileInfo.isFile() && destFileInfo.isDir()){
destCopy = destFileInfo.absoluteFilePath() + QDir::separator() + srcFileInfo.fileName();
}
if(force){
qDir.remove(destCopy);
}
qDir.rename(src, destCopy);
} else {
QDir qDir;
QFileInfo srcFileInfo(src);
QString destCopy = dest;
if (srcFileInfo.isFile() && destFileInfo.isDir()) {
destCopy = destFileInfo.absoluteFilePath() + QDir::separator() +
srcFileInfo.fileName();
}
// reecrypt all files under the new folder
if(destFileInfo.isDir()){
reencryptPath(destFileInfo.absoluteFilePath());
}else if(destFileInfo.isFile()){
reencryptPath(destFileInfo.dir().path());
if (force) {
qDir.remove(destCopy);
}
qDir.rename(src, destCopy);
}
// reecrypt all files under the new folder
if (destFileInfo.isDir()) {
reencryptPath(destFileInfo.absoluteFilePath());
} else if (destFileInfo.isFile()) {
reencryptPath(destFileInfo.dir().path());
}
}

void ImitatePass::Copy(const QString src, const QString dest,
const bool force) {
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "cp";
if (force) {
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_COPY, args);

void ImitatePass::Copy(const QString src, const QString dest, const bool force)
{
QFileInfo destFileInfo(dest);
if (QtPassSettings::isUseGit()) {
QStringList args;
args << "cp";
if(force){
args << "-f";
}
args << src;
args << dest;
executeGit(GIT_COPY, args);

QString message=QString("copied from %1 to %2 using QTPass.");
message= message.arg(src).arg(dest);
GitCommit("", message);
if(QtPassSettings::isAutoPush()){
GitPush();
}

} else {
QDir qDir;
if(force){
qDir.remove(dest);
}
QFile::copy(src, dest);
QString message = QString("copied from %1 to %2 using QTPass.");
message = message.arg(src).arg(dest);
GitCommit("", message);
if (QtPassSettings::isAutoPush()) {
GitPush();
}
// reecrypt all files under the new folder
if(destFileInfo.isDir()){
reencryptPath(destFileInfo.absoluteFilePath());
}else if(destFileInfo.isFile()){
reencryptPath(destFileInfo.dir().path());

} else {
QDir qDir;
if (force) {
qDir.remove(dest);
}
QFile::copy(src, dest);
}
// reecrypt all files under the new folder
if (destFileInfo.isDir()) {
reencryptPath(destFileInfo.absoluteFilePath());
} else if (destFileInfo.isFile()) {
reencryptPath(destFileInfo.dir().path());
}
}
2 changes: 0 additions & 2 deletions src/imitatepass.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ImitatePass : public Pass {
virtual void GitPull_b() Q_DECL_OVERRIDE;
virtual void GitPush() Q_DECL_OVERRIDE;
virtual void Show(QString file) Q_DECL_OVERRIDE;
virtual int Show_b(QString file) Q_DECL_OVERRIDE;
virtual void Insert(QString file, QString value,
bool overwrite = false) Q_DECL_OVERRIDE;
virtual void Remove(QString file, bool isDir = false) Q_DECL_OVERRIDE;
Expand All @@ -39,7 +38,6 @@ class ImitatePass : public Pass {
signals:
void startReencryptPath();
void endReencryptPath();
void lastDecrypt(QString);

// Pass interface
public:
Expand Down
Loading

0 comments on commit 696e797

Please sign in to comment.