diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2018-12-10 11:58:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-10 11:58:36 +0100 |
commit | 5918e60156746b463d93cb1749e0685cfe31b73b (patch) | |
tree | af6a3078bd3cbdb883d68cc3ad1bbef7e29d9eac | |
parent | 8fabd7edf4736597ade39ac365d5864113fd0199 (diff) | |
parent | 3b10fd3a556f5b5fd3b4ec13951c006d6dd328c1 (diff) |
Merge pull request #431 from rdoeffinger/wslsupport
Support for using WSL binaries on Windows
-rw-r--r-- | src/configdialog.cpp | 4 | ||||
-rw-r--r-- | src/executor.cpp | 22 | ||||
-rw-r--r-- | src/executor.h | 12 | ||||
-rw-r--r-- | src/imitatepass.cpp | 46 | ||||
-rw-r--r-- | src/pass.cpp | 3 | ||||
-rw-r--r-- | src/util.cpp | 15 |
6 files changed, 72 insertions, 30 deletions
diff --git a/src/configdialog.cpp b/src/configdialog.cpp index ae07ad2c..d2d88bb4 100644 --- a/src/configdialog.cpp +++ b/src/configdialog.cpp @@ -538,7 +538,7 @@ void ConfigDialog::wizard() { QString gpg = ui->gpgPath->text(); // QString gpg = mainWindow->getGpgExecutable(); - if (!QFile(gpg).exists()) { + if (!gpg.startsWith("wsl ") && !QFile(gpg).exists()) { criticalMessage( tr("GnuPG not found"), tr("Please install GnuPG on your system.<br>Install " @@ -555,7 +555,7 @@ void ConfigDialog::wizard() { dbg() << names; #endif - if (QFile(gpg).exists() && names.empty()) { + if ((gpg.startsWith("wsl ") || QFile(gpg).exists()) && names.empty()) { KeygenDialog d(this); if (!d.exec()) return; diff --git a/src/executor.cpp b/src/executor.cpp index c39b76a8..fc452805 100644 --- a/src/executor.cpp +++ b/src/executor.cpp @@ -31,7 +31,14 @@ void Executor::executeNext() { running = true; if (!i.workingDir.isEmpty()) m_process.setWorkingDirectory(i.workingDir); - m_process.start(i.app, i.args); + if (i.app.startsWith("wsl ")) + { + QStringList tmp = i.args; + QString app = i.app; + tmp.prepend(app.remove(0, 4)); + m_process.start("wsl", tmp); + } else + m_process.start(i.app, i.args); if (!i.input.isEmpty()) { m_process.waitForStarted(-1); QByteArray data = i.input.toUtf8(); @@ -111,8 +118,9 @@ void Executor::execute(int id, const QString &workDir, const QString &app, #endif return; } - QString appPath = - QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(app); + QString appPath = app; + if (!appPath.startsWith("wsl ")) + appPath = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(app); m_execQueue.push_back( {id, appPath, args, input, readStdout, readStderr, workDir}); executeNext(); @@ -154,7 +162,13 @@ int Executor::executeBlocking(QString app, const QStringList &args, QString input, QString *process_out, QString *process_err) { QProcess internal; - internal.start(app, args); + if (app.startsWith("wsl ")) + { + QStringList tmp = args; + tmp.prepend(app.remove(0, 4)); + internal.start("wsl", tmp); + } else + internal.start(app, args); if (!input.isEmpty()) { QByteArray data = input.toUtf8(); internal.waitForStarted(-1); diff --git a/src/executor.h b/src/executor.h index 2a8b67cd..2d96be22 100644 --- a/src/executor.h +++ b/src/executor.h @@ -73,13 +73,13 @@ public: const QStringList &args, QString input = QString(), bool readStdout = false, bool readStderr = true); - int executeBlocking(QString app, const QStringList &args, - QString input = QString(), - QString *process_out = Q_NULLPTR, - QString *process_err = Q_NULLPTR); + static int executeBlocking(QString app, const QStringList &args, + QString input = QString(), + QString *process_out = Q_NULLPTR, + QString *process_err = Q_NULLPTR); - int executeBlocking(QString app, const QStringList &args, - QString *process_out, QString *process_err = Q_NULLPTR); + static int executeBlocking(QString app, const QStringList &args, + QString *process_out, QString *process_err = Q_NULLPTR); void setEnvironment(const QStringList &env); diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index cf8a1586..3d169a99 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -14,11 +14,25 @@ using namespace Enums; */ ImitatePass::ImitatePass() {} +static QString pgit(const QString &path) +{ + if (!QtPassSettings::getGitExecutable().startsWith("wsl ")) return path; + QString res = "$(wslpath " + path + ")"; + return res.replace('\\', '/'); +} + +static QString pgpg(const QString &path) +{ + if (!QtPassSettings::getGpgExecutable().startsWith("wsl ")) return path; + QString res = "$(wslpath " + path + ")"; + return res.replace('\\', '/'); +} + /** * @brief ImitatePass::GitInit git init wrapper */ void ImitatePass::GitInit() { - executeGit(GIT_INIT, {"init", QtPassSettings::getPassStore()}); + executeGit(GIT_INIT, {"init", pgit(QtPassSettings::getPassStore())}); } /** @@ -48,7 +62,7 @@ void ImitatePass::GitPush() { void ImitatePass::Show(QString file) { file = QtPassSettings::getPassStore() + file + ".gpg"; QStringList args = {"-d", "--quiet", "--yes", "--no-encrypt-to", - "--batch", "--use-agent", file}; + "--batch", "--use-agent", pgpg(file)}; executeGpg(PASS_SHOW, args); } @@ -82,7 +96,7 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) { "file missing or invalid.")); return; } - QStringList args = {"--batch", "-eq", "--output", file}; + QStringList args = {"--batch", "-eq", "--output", pgpg(file)}; for (auto &r : recipients) { args.append("-r"); args.append(r); @@ -94,7 +108,7 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) { if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) { // TODO(bezet) why not? if (!overwrite) - executeGit(GIT_ADD, {"add", file}); + executeGit(GIT_ADD, {"add", pgit(file)}); QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(file); path.replace(QRegExp("\\.gpg$"), ""); QString msg = @@ -110,7 +124,7 @@ void ImitatePass::Insert(QString file, QString newValue, bool overwrite) { * @param msg */ void ImitatePass::GitCommit(const QString &file, const QString &msg) { - executeGit(GIT_COMMIT, {"commit", "-m", msg, "--", file}); + executeGit(GIT_COMMIT, {"commit", "-m", msg, "--", pgit(file)}); } /** @@ -122,7 +136,7 @@ void ImitatePass::Remove(QString file, bool isDir) { if (!isDir) file += ".gpg"; if (QtPassSettings::isUseGit()) { - executeGit(GIT_RM, {"rm", (isDir ? "-rf" : "-f"), file}); + executeGit(GIT_RM, {"rm", (isDir ? "-rf" : "-f"), pgit(file)}); // TODO(bezet): commit message used to have pass-like file name inside(ie. // getFile(file, true) GitCommit(file, "Remove for " + file + " using QtPass."); @@ -180,7 +194,7 @@ void ImitatePass::Init(QString path, const QList<UserInfo> &users) { if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit() && !QtPassSettings::getGitExecutable().isEmpty()) { if (addFile) - executeGit(GIT_ADD, {"add", gpgIdFile}); + executeGit(GIT_ADD, {"add", pgit(gpgIdFile)}); QString path = gpgIdFile; path.replace(QRegExp("\\.gpg$"), ""); GitCommit(gpgIdFile, "Added " + path + " using QtPass."); @@ -243,7 +257,7 @@ void ImitatePass::reencryptPath(QString dir) { // TODO(bezet): enable --with-colons for better future-proofness? QStringList args = { "-v", "--no-secmem-warning", "--no-permission-warning", - "--list-only", "--keyid-format=long", fileName}; + "--list-only", "--keyid-format=long", pgpg(fileName)}; QString keys, err; exec.executeBlocking(QtPassSettings::getGpgExecutable(), args, &keys, &err); QStringList actualKeys; @@ -268,7 +282,7 @@ void ImitatePass::reencryptPath(QString dir) { #endif QString local_lastDecrypt = "Could not decrypt"; args = QStringList{"-d", "--quiet", "--yes", "--no-encrypt-to", - "--batch", "--use-agent", fileName}; + "--batch", "--use-agent", pgpg(fileName)}; exec.executeBlocking(QtPassSettings::getGpgExecutable(), args, &local_lastDecrypt); @@ -284,7 +298,7 @@ void ImitatePass::reencryptPath(QString dir) { "file missing or invalid.")); return; } - args = QStringList{"--yes", "--batch", "-eq", "--output", fileName}; + args = QStringList{"--yes", "--batch", "-eq", "--output", pgpg(fileName)}; for (auto &i : recipients) { args.append("-r"); args.append(i); @@ -295,12 +309,12 @@ void ImitatePass::reencryptPath(QString dir) { if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) { exec.executeBlocking(QtPassSettings::getGitExecutable(), - {"add", fileName}); + {"add", pgit(fileName)}); QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(fileName); path.replace(QRegExp("\\.gpg$"), ""); exec.executeBlocking(QtPassSettings::getGitExecutable(), - {"commit", fileName, "-m", + {"commit", pgit(fileName), "-m", "Edit for " + path + " using QtPass."}); } @@ -329,8 +343,8 @@ void ImitatePass::Move(const QString src, const QString dest, if (force) { args << "-f"; } - args << src; - args << dest; + args << pgit(src); + args << pgit(dest); executeGit(GIT_MOVE, args); QString message = QString("moved from %1 to %2 using QTPass."); @@ -367,8 +381,8 @@ void ImitatePass::Copy(const QString src, const QString dest, if (force) { args << "-f"; } - args << src; - args << dest; + args << pgit(src); + args << pgit(dest); executeGit(GIT_COPY, args); QString message = QString("copied from %1 to %2 using QTPass."); diff --git a/src/pass.cpp b/src/pass.cpp index 788b868b..7eb8d7a4 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -23,6 +23,7 @@ Pass::Pass() : wrapperRunning(false), env(QProcess::systemEnvironment()) { // SIGNAL(error(QProcess::ProcessError))); connect(&exec, &Executor::starting, this, &Pass::startingExecuteWrapper); + env.append("WSLENV=PASSWORD_STORE_DIR/p"); } void Pass::executeWrapper(PROCESS id, const QString &app, @@ -233,7 +234,7 @@ void Pass::finished(int id, int exitCode, const QString &out, * switching profiles) */ void Pass::updateEnv() { - QStringList store = env.filter("PASSWORD_STORE_DIR"); + QStringList store = env.filter("PASSWORD_STORE_DIR="); // put PASSWORD_STORE_DIR in env if (store.isEmpty()) { // dbg()<< "Added diff --git a/src/util.cpp b/src/util.cpp index ac69bae7..147d609c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -110,6 +110,17 @@ QString Util::findBinaryInPath(QString binary) { break; } } +#ifdef Q_OS_WIN + if (ret.isEmpty()) + { + binary.remove(0, 1); + binary.prepend("wsl "); + QString out, err; + if (Executor::executeBlocking(binary, {"--version"}, &out, &err) == 0 && + !out.isEmpty() && err.isEmpty()) + ret = binary; + } +#endif return ret; } @@ -121,7 +132,9 @@ QString Util::findBinaryInPath(QString binary) { bool Util::checkConfig() { return !QFile(QDir(QtPassSettings::getPassStore()).filePath(".gpg-id")) .exists() || - (!QFile(QtPassSettings::getPassExecutable()).exists() && + (!QtPassSettings::getPassExecutable().startsWith("wsl ") && + !QFile(QtPassSettings::getPassExecutable()).exists() && + !QtPassSettings::getGpgExecutable().startsWith("wsl ") && !QFile(QtPassSettings::getGpgExecutable()).exists()); } |