diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2018-08-30 01:18:52 +0200 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2018-11-04 18:27:48 +0100 |
commit | fd3582c395ee81916cbeecb24640ba13f77b85cd (patch) | |
tree | e88ee1108eb3dfcd77827d7ad95a304a02c4b109 /src/imitatepass.cpp | |
parent | 32ea1ad39a51b0d1b7e7b24351ae1139c3f5dbec (diff) |
Add support for using Linux binaries on Windows.
Uses WSL, selected by prefixing the binaries with "wsl ".
Diffstat (limited to 'src/imitatepass.cpp')
-rw-r--r-- | src/imitatepass.cpp | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index f1c84e40..862be677 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."); |