diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2019-04-17 11:26:56 +0200 |
---|---|---|
committer | Anne Jan Brouwer <brouwer@annejan.com> | 2019-04-17 11:26:56 +0200 |
commit | f2b2f6715215e83b27d5b067a2b1a9e890bd8be7 (patch) | |
tree | 85d8768d0c0e3052ab21541e3b73f2c4af899bb7 /src/imitatepass.cpp | |
parent | 5eae57663c53467b946ea7a7b5935766afebc90b (diff) | |
parent | 3698ff096cffec3541253ba1e745c389df0118c2 (diff) |
Updated to current master
Diffstat (limited to 'src/imitatepass.cpp')
-rw-r--r-- | src/imitatepass.cpp | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/src/imitatepass.cpp b/src/imitatepass.cpp index a0b19d1e..659f97aa 100644 --- a/src/imitatepass.cpp +++ b/src/imitatepass.cpp @@ -15,11 +15,25 @@ using namespace Enums; */ ImitatePass::ImitatePass() = default; +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,8 +62,8 @@ 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}; + QStringList args = {"-d", "--quiet", "--yes", "--no-encrypt-to", + "--batch", "--use-agent", pgpg(file)}; executeGpg(PASS_SHOW, args); } @@ -83,7 +97,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); @@ -95,7 +109,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 = @@ -111,7 +125,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)}); } /** @@ -123,7 +137,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."); @@ -181,7 +195,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."); @@ -244,12 +258,12 @@ void ImitatePass::reencryptPath(const 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; keys += err; - QStringList key = keys.split("\n"); + QStringList key = keys.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); QListIterator<QString> itr(key); while (itr.hasNext()) { QString current = itr.next(); @@ -268,8 +282,9 @@ void ImitatePass::reencryptPath(const QString &dir) { dbg() << "reencrypt " << fileName << " for " << gpgId; #endif QString local_lastDecrypt = "Could not decrypt"; - args = QStringList{"-d", "--quiet", "--yes", "--no-encrypt-to", - "--batch", "--use-agent", fileName}; + args = QStringList{ + "-d", "--quiet", "--yes", "--no-encrypt-to", + "--batch", "--use-agent", pgpg(fileName)}; exec.executeBlocking(QtPassSettings::getGpgExecutable(), args, &local_lastDecrypt); @@ -285,7 +300,8 @@ void ImitatePass::reencryptPath(const 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); @@ -296,12 +312,12 @@ void ImitatePass::reencryptPath(const 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."}); } @@ -330,8 +346,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."); @@ -368,8 +384,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."); |