• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 23851408557

01 Apr 2026 01:35PM UTC coverage: 20.082%. Remained the same
23851408557

push

github

web-flow
Potential fix for 1 code quality finding (#889)

* Apply suggested fix to src/imitatepass.cpp from Copilot Autofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Update src/imitatepass.cpp

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

0 of 1 new or added line in 1 file covered. (0.0%)

1026 of 5109 relevant lines covered (20.08%)

7.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.23
/src/imitatepass.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "imitatepass.h"
4
#include "qtpasssettings.h"
5
#include "util.h"
6
#include <QDirIterator>
7
#include <QRegularExpression>
8
#include <utility>
9

10
#ifdef QT_DEBUG
11
#include "debughelper.h"
12
#endif
13

14
using Enums::CLIPBOARD_ALWAYS;
15
using Enums::CLIPBOARD_NEVER;
16
using Enums::CLIPBOARD_ON_DEMAND;
17
using Enums::GIT_ADD;
18
using Enums::GIT_COMMIT;
19
using Enums::GIT_COPY;
20
using Enums::GIT_INIT;
21
using Enums::GIT_MOVE;
22
using Enums::GIT_PULL;
23
using Enums::GIT_PUSH;
24
using Enums::GIT_RM;
25
using Enums::GPG_GENKEYS;
26
using Enums::INVALID;
27
using Enums::PASS_COPY;
28
using Enums::PASS_INIT;
29
using Enums::PASS_INSERT;
30
using Enums::PASS_MOVE;
31
using Enums::PASS_OTP_GENERATE;
32
using Enums::PASS_REMOVE;
33
using Enums::PASS_SHOW;
34
using Enums::PROCESS_COUNT;
35

36
/**
37
 * @brief ImitatePass::ImitatePass for situaions when pass is not available
38
 * we imitate the behavior of pass https://www.passwordstore.org/
39
 */
40
ImitatePass::ImitatePass() = default;
20✔
41

42
static auto pgit(const QString &path) -> QString {
×
43
  if (!QtPassSettings::getGitExecutable().startsWith("wsl ")) {
×
44
    return path;
45
  }
46
  QString res = "$(wslpath " + path + ")";
×
47
  return res.replace('\\', '/');
×
48
}
49

50
static auto pgpg(const QString &path) -> QString {
×
51
  if (!QtPassSettings::getGpgExecutable().startsWith("wsl ")) {
×
52
    return path;
53
  }
54
  QString res = "$(wslpath " + path + ")";
×
55
  return res.replace('\\', '/');
×
56
}
57

58
/**
59
 * @brief ImitatePass::GitInit git init wrapper
60
 */
61
void ImitatePass::GitInit() {
×
62
  executeGit(GIT_INIT, {"init", pgit(QtPassSettings::getPassStore())});
×
63
}
×
64

65
/**
66
 * @brief ImitatePass::GitPull git init wrapper
67
 */
68
void ImitatePass::GitPull() { executeGit(GIT_PULL, {"pull"}); }
×
69

70
/**
71
 * @brief ImitatePass::GitPull_b git pull wrapper
72
 */
73
void ImitatePass::GitPull_b() {
×
74
  Executor::executeBlocking(QtPassSettings::getGitExecutable(), {"pull"});
×
75
}
×
76

77
/**
78
 * @brief ImitatePass::GitPush git init wrapper
79
 */
80
void ImitatePass::GitPush() {
×
81
  if (QtPassSettings::isUseGit()) {
×
82
    executeGit(GIT_PUSH, {"push"});
×
83
  }
84
}
×
85

86
/**
87
 * @brief ImitatePass::Show shows content of file
88
 */
89
void ImitatePass::Show(QString file) {
×
90
  file = QtPassSettings::getPassStore() + file + ".gpg";
×
91
  QStringList args = {"-d",      "--quiet",     "--yes",   "--no-encrypt-to",
92
                      "--batch", "--use-agent", pgpg(file)};
×
93
  executeGpg(PASS_SHOW, args);
×
94
}
×
95

96
/**
97
 * @brief ImitatePass::OtpGenerate generates an otp code
98
 */
99
void ImitatePass::OtpGenerate(QString file) {
×
100
#ifdef QT_DEBUG
101
  dbg() << "No OTP generation code for fake pass yet, attempting for file: " +
102
               file;
103
#else
104
  Q_UNUSED(file)
105
#endif
106
}
×
107

108
/**
109
 * @brief ImitatePass::Insert create new file with encrypted content
110
 *
111
 * @param file      file to be created
112
 * @param newValue  value to be stored in file
113
 * @param overwrite whether to overwrite existing file
114
 */
115
void ImitatePass::Insert(QString file, QString newValue, bool overwrite) {
×
116
  file = file + ".gpg";
×
117
  QString gpgIdPath = Pass::getGpgIdPath(file);
×
118
  if (!verifyGpgIdFile(gpgIdPath)) {
×
119
    emit critical(tr("Check .gpgid file signature!"),
×
120
                  tr("Signature for %1 is invalid.").arg(gpgIdPath));
×
121
    return;
×
122
  }
123
  transactionHelper trans(this, PASS_INSERT);
×
124
  QStringList recipients = Pass::getRecipientList(file);
×
125
  if (recipients.isEmpty()) {
×
126
    // Already emit critical signal to notify user of error - no need to throw
127
    emit critical(tr("Can not edit"),
×
128
                  tr("Could not read encryption key to use, .gpg-id "
×
129
                     "file missing or invalid."));
130
    return;
131
  }
132
  QStringList args = {"--batch", "-eq", "--output", pgpg(file)};
×
133
  for (auto &r : recipients) {
×
134
    args.append("-r");
×
135
    args.append(r);
136
  }
137
  if (overwrite) {
×
138
    args.append("--yes");
×
139
  }
140
  args.append("-");
×
141
  executeGpg(PASS_INSERT, args, newValue);
×
142
  if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) {
×
143
    // Git is used when enabled - this is the standard pass workflow
144
    if (!overwrite) {
×
145
      executeGit(GIT_ADD, {"add", pgit(file)});
×
146
    }
147
    QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(file);
×
148
    path.replace(Util::endsWithGpg(), "");
×
149
    QString msg =
150
        QString(overwrite ? "Edit" : "Add") + " for " + path + " using QtPass.";
×
151
    GitCommit(file, msg);
×
152
  }
153
}
×
154

155
/**
156
 * @brief ImitatePass::GitCommit commit a file to git with an appropriate commit
157
 * message
158
 * @param file
159
 * @param msg
160
 */
161
void ImitatePass::GitCommit(const QString &file, const QString &msg) {
×
162
  if (file.isEmpty()) {
×
163
    executeGit(GIT_COMMIT, {"commit", "-m", msg});
×
164
  } else {
165
    executeGit(GIT_COMMIT, {"commit", "-m", msg, "--", pgit(file)});
×
166
  }
167
}
×
168

169
/**
170
 * @brief ImitatePass::Remove custom implementation of "pass remove"
171
 */
172
void ImitatePass::Remove(QString file, bool isDir) {
×
173
  file = QtPassSettings::getPassStore() + file;
×
174
  transactionHelper trans(this, PASS_REMOVE);
×
175
  if (!isDir) {
×
176
    file += ".gpg";
×
177
  }
178
  if (QtPassSettings::isUseGit()) {
×
179
    executeGit(GIT_RM, {"rm", (isDir ? "-rf" : "-f"), pgit(file)});
×
180
    // Normalize path the same way as add/edit operations
181
    QString path = QDir(QtPassSettings::getPassStore()).relativeFilePath(file);
×
182
    path.replace(Util::endsWithGpg(), "");
×
183
    GitCommit(file, "Remove for " + path + " using QtPass.");
×
184
  } else {
185
    if (isDir) {
×
186
      QDir dir(file);
×
187
      dir.removeRecursively();
×
188
    } else {
×
189
      QFile(file).remove();
×
190
    }
191
  }
192
}
×
193

194
/**
195
 * @brief ImitatePass::Init initialize pass repository
196
 *
197
 * @param path      path in which new password-store will be created
198
 * @param users     list of users who shall be able to decrypt passwords in
199
 * path
200
 */
201
auto ImitatePass::checkSigningKeys(const QStringList &signingKeys) -> bool {
×
202
  QString out;
×
203
  QStringList args =
204
      QStringList{"--status-fd=1", "--list-secret-keys"} + signingKeys;
×
205
  Executor::executeBlocking(QtPassSettings::getGpgExecutable(), args, &out);
×
206
  for (auto &key : signingKeys) {
×
207
    if (out.contains("[GNUPG:] KEY_CONSIDERED " + key)) {
×
208
      return true;
209
    }
210
  }
211
  return false;
212
}
×
213

214
void ImitatePass::writeGpgIdFile(const QString &gpgIdFile,
×
215
                                 const QList<UserInfo> &users) {
216
  QFile gpgId(gpgIdFile);
×
217
  if (!gpgId.open(QIODevice::WriteOnly | QIODevice::Text)) {
×
218
    emit critical(tr("Cannot update"),
×
219
                  tr("Failed to open .gpg-id for writing."));
×
220
    return;
221
  }
222
  bool secret_selected = false;
223
  for (const UserInfo &user : users) {
×
224
    if (user.enabled) {
×
225
      gpgId.write((user.key_id + "\n").toUtf8());
×
226
      secret_selected |= user.have_secret;
×
227
    }
228
  }
229
  gpgId.close();
×
230
  if (!secret_selected) {
×
231
    emit critical(
×
232
        tr("Check selected users!"),
×
233
        tr("None of the selected keys have a secret key available.\n"
×
234
           "You will not be able to decrypt any newly added passwords!"));
235
  }
236
}
×
237

238
void ImitatePass::signGpgIdFile(const QString &gpgIdFile,
×
239
                                const QStringList &signingKeys) {
240
  QStringList args;
×
241
  for (auto &key : signingKeys) {
×
242
    args.append(QStringList{"--default-key", key});
×
243
  }
244
  args.append(QStringList{"--yes", "--detach-sign", gpgIdFile});
×
245
  Executor::executeBlocking(QtPassSettings::getGpgExecutable(), args);
×
246
  if (!verifyGpgIdFile(gpgIdFile)) {
×
247
    emit critical(tr("Check .gpgid file signature!"),
×
248
                  tr("Signature for %1 is invalid.").arg(gpgIdFile));
×
249
  }
250
}
×
251

252
void ImitatePass::gitAddGpgId(const QString &gpgIdFile,
×
253
                              const QString &gpgIdSigFile, bool addFile,
254
                              bool addSigFile) {
255
  if (addFile) {
×
256
    executeGit(GIT_ADD, {"add", pgit(gpgIdFile)});
×
257
  }
258
  QString commitPath = gpgIdFile;
259
  commitPath.replace(Util::endsWithGpg(), "");
×
260
  GitCommit(gpgIdFile, "Added " + commitPath + " using QtPass.");
×
261
  if (!addSigFile) {
×
262
    return;
263
  }
264
  executeGit(GIT_ADD, {"add", pgit(gpgIdSigFile)});
×
265
  commitPath = gpgIdSigFile;
×
266
  commitPath.replace(QRegularExpression("\\.gpg$"), "");
×
267
  GitCommit(gpgIdSigFile, "Added " + commitPath + " using QtPass.");
×
268
}
×
269

270
void ImitatePass::Init(QString path, const QList<UserInfo> &users) {
×
271
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
272
  QStringList signingKeys =
273
      QtPassSettings::getPassSigningKey().split(" ", Qt::SkipEmptyParts);
×
274
#else
275
  QStringList signingKeys =
276
      QtPassSettings::getPassSigningKey().split(" ", QString::SkipEmptyParts);
277
#endif
278
  QString gpgIdSigFile = path + ".gpg-id.sig";
×
279
  bool addSigFile = false;
280
  if (!signingKeys.isEmpty()) {
×
281
    if (!checkSigningKeys(signingKeys)) {
×
282
      emit critical(tr("No signing key!"),
×
283
                    tr("None of the secret signing keys is available.\n"
×
284
                       "You will not be able to change the user list!"));
285
      return;
×
286
    }
287
    QFileInfo checkFile(gpgIdSigFile);
×
288
    if (!checkFile.exists() || !checkFile.isFile()) {
×
289
      addSigFile = true;
290
    }
291
  }
×
292

293
  QString gpgIdFile = path + ".gpg-id";
×
294
  bool addFile = false;
295
  transactionHelper trans(this, PASS_INIT);
×
296
  if (QtPassSettings::isAddGPGId(true)) {
×
297
    QFileInfo checkFile(gpgIdFile);
×
298
    if (!checkFile.exists() || !checkFile.isFile()) {
×
299
      addFile = true;
300
    }
301
  }
×
302
  writeGpgIdFile(gpgIdFile, users);
×
303

304
  if (!signingKeys.isEmpty()) {
×
305
    signGpgIdFile(gpgIdFile, signingKeys);
×
306
  }
307

308
  if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit() &&
×
309
      !QtPassSettings::getGitExecutable().isEmpty()) {
×
310
    gitAddGpgId(gpgIdFile, gpgIdSigFile, addFile, addSigFile);
×
311
  }
312
  reencryptPath(path);
×
313
}
314

315
/**
316
 * @brief ImitatePass::verifyGpgIdFile verify detached gpgid file signature.
317
 * @param file which gpgid file.
318
 * @return was verification succesful?
319
 */
320
auto ImitatePass::verifyGpgIdFile(const QString &file) -> bool {
×
321
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
322
  QStringList signingKeys =
323
      QtPassSettings::getPassSigningKey().split(" ", Qt::SkipEmptyParts);
×
324
#else
325
  QStringList signingKeys =
326
      QtPassSettings::getPassSigningKey().split(" ", QString::SkipEmptyParts);
327
#endif
328
  if (signingKeys.isEmpty()) {
×
329
    return true;
330
  }
331
  QString out;
×
332
  QStringList args =
333
      QStringList{"--verify", "--status-fd=1", pgpg(file) + ".sig", pgpg(file)};
×
334
  Executor::executeBlocking(QtPassSettings::getGpgExecutable(), args, &out);
×
335
  QRegularExpression re(
336
      R"(^\[GNUPG:\] VALIDSIG ([A-F0-9]{40}) .* ([A-F0-9]{40})\r?$)",
337
      QRegularExpression::MultilineOption);
×
338
  QRegularExpressionMatch m = re.match(out);
×
339
  if (!m.hasMatch()) {
×
340
    return false;
341
  }
342
  QStringList fingerprints = m.capturedTexts();
×
343
  fingerprints.removeFirst();
×
344
  for (auto &key : signingKeys) {
×
345
    if (fingerprints.contains(key)) {
×
346
      return true;
×
347
    }
348
  }
349
  return false;
×
350
}
×
351

352
/**
353
 * @brief ImitatePass::removeDir delete folder recursive.
354
 * @param dirName which folder.
355
 * @return was removal succesful?
356
 */
357
auto ImitatePass::removeDir(const QString &dirName) -> bool {
1✔
358
  bool result = true;
359
  QDir dir(dirName);
1✔
360

361
  if (dir.exists(dirName)) {
1✔
362
    for (const QFileInfo &info :
363
         dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
364
                               QDir::AllDirs | QDir::Files,
365
                           QDir::DirsFirst)) {
1✔
366
      if (info.isDir()) {
×
367
        result = removeDir(info.absoluteFilePath());
×
368
      } else {
369
        result = QFile::remove(info.absoluteFilePath());
×
370
      }
371

372
      if (!result) {
×
373
        return result;
374
      }
375
    }
376
    result = dir.rmdir(dirName);
1✔
377
  }
378
  return result;
379
}
1✔
380

381
/**
382
 * @brief ImitatePass::reencryptPath reencrypt all files under the chosen
383
 * directory
384
 *
385
 * This is stil quite experimental..
386
 * @param dir
387
 */
388
void ImitatePass::verifyGpgIdForDir(const QString &file,
×
389
                                    QStringList &gpgIdFilesVerified,
390
                                    QStringList &gpgId) {
391
  QString gpgIdPath = Pass::getGpgIdPath(file);
×
392
  if (gpgIdFilesVerified.contains(gpgIdPath)) {
×
393
    return;
394
  }
395
  if (!verifyGpgIdFile(gpgIdPath)) {
×
396
    emit critical(tr("Check .gpgid file signature!"),
×
397
                  tr("Signature for %1 is invalid.").arg(gpgIdPath));
×
398
    emit endReencryptPath();
×
399
    return;
400
  }
401
  gpgIdFilesVerified.append(gpgIdPath);
402
  gpgId = getRecipientList(file);
×
403
  gpgId.sort();
404
}
405

406
auto ImitatePass::getKeysFromFile(const QString &fileName) -> QStringList {
×
407
  QStringList args = {
408
      "-v",          "--no-secmem-warning", "--no-permission-warning",
409
      "--list-only", "--keyid-format=long", pgpg(fileName)};
×
410
  QString keys;
×
411
  QString err;
×
412
  Executor::executeBlocking(QtPassSettings::getGpgExecutable(), args, &keys,
×
413
                            &err);
414
  QStringList actualKeys;
×
415
  keys += err;
416
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
417
  QStringList key = keys.split(Util::newLinesRegex(), Qt::SkipEmptyParts);
×
418
#else
419
  QStringList key = keys.split(Util::newLinesRegex(), QString::SkipEmptyParts);
420
#endif
421
  QListIterator<QString> itr(key);
422
  while (itr.hasNext()) {
×
423
    QString current = itr.next();
424
    QStringList cur = current.split(" ");
×
425
    if (cur.length() > 4) {
×
426
      QString actualKey = cur.takeAt(4);
×
427
      if (actualKey.length() == 16) {
×
428
        actualKeys << actualKey;
429
      }
430
    }
431
  }
432
  actualKeys.sort();
433
  return actualKeys;
×
434
}
×
435

436
void ImitatePass::reencryptSingleFile(const QString &fileName,
×
437
                                      const QStringList &recipients) {
438
#ifdef QT_DEBUG
439
  dbg() << "reencrypt " << fileName << " for " << recipients;
440
#endif
441
  QString local_lastDecrypt = "Could not decrypt";
×
442
  QStringList args = {
443
      "-d",      "--quiet",     "--yes",       "--no-encrypt-to",
444
      "--batch", "--use-agent", pgpg(fileName)};
×
445
  Executor::executeBlocking(QtPassSettings::getGpgExecutable(), args,
×
446
                            &local_lastDecrypt);
447

448
  if (local_lastDecrypt.isEmpty() || local_lastDecrypt == "Could not decrypt") {
×
449
#ifdef QT_DEBUG
450
    dbg() << "Decrypt error on re-encrypt";
451
#endif
452
    return;
×
453
  }
454

455
  if (local_lastDecrypt.right(1) != "\n") {
×
456
    local_lastDecrypt += "\n";
×
457
  }
458

459
  QStringList recipientsList = Pass::getRecipientList(fileName);
×
460
  if (recipientsList.isEmpty()) {
×
461
    emit critical(tr("Can not edit"),
×
462
                  tr("Could not read encryption key to use, .gpg-id "
×
463
                     "file missing or invalid."));
464
    return;
465
  }
466
  args = QStringList{"--yes", "--batch", "-eq", "--output", pgpg(fileName)};
×
467
  for (auto &i : recipientsList) {
×
468
    args.append("-r");
×
469
    args.append(i);
470
  }
471
  args.append("-");
×
472
  Executor::executeBlocking(QtPassSettings::getGpgExecutable(), args,
×
473
                            local_lastDecrypt);
474

475
  if (!QtPassSettings::isUseWebDav() && QtPassSettings::isUseGit()) {
×
476
    Executor::executeBlocking(QtPassSettings::getGitExecutable(),
×
477
                              {"add", pgit(fileName)});
478
    QString path =
479
        QDir(QtPassSettings::getPassStore()).relativeFilePath(fileName);
×
480
    path.replace(Util::endsWithGpg(), "");
×
481
    Executor::executeBlocking(QtPassSettings::getGitExecutable(),
×
482
                              {"commit", pgit(fileName), "-m",
483
                               "Edit for " + path + " using QtPass."});
×
484
  }
485
}
×
486

487
void ImitatePass::reencryptPath(const QString &dir) {
×
488
  emit statusMsg(tr("Re-encrypting from folder %1").arg(dir), 3000);
×
489
  emit startReencryptPath();
×
490
  if (QtPassSettings::isAutoPull()) {
×
491
    emit statusMsg(tr("Updating password-store"), 2000);
×
492
    GitPull_b();
×
493
  }
494
  QDir currentDir;
×
495
  QDirIterator gpgFiles(dir, QStringList() << "*.gpg", QDir::Files,
×
496
                        QDirIterator::Subdirectories);
×
497
  QStringList gpgIdFilesVerified;
×
498
  QStringList gpgId;
×
499
  while (gpgFiles.hasNext()) {
×
500
    QString fileName = gpgFiles.next();
×
501
    if (gpgFiles.fileInfo().path() != currentDir.path()) {
×
502
      verifyGpgIdForDir(fileName, gpgIdFilesVerified, gpgId);
×
503
      if (gpgId.isEmpty() && !gpgIdFilesVerified.isEmpty()) {
×
504
        return;
505
      }
506
    }
507
    QStringList actualKeys = getKeysFromFile(fileName);
×
508
    if (actualKeys != gpgId) {
×
509
      reencryptSingleFile(fileName, gpgId);
×
510
    }
511
  }
512
  if (QtPassSettings::isAutoPush()) {
×
513
    emit statusMsg(tr("Updating password-store"), 2000);
×
514
    GitPush();
×
515
  }
516
  emit endReencryptPath();
×
517
}
×
518

519
auto ImitatePass::resolveMoveDestination(const QString &src,
5✔
520
                                         const QString &dest, bool force)
521
    -> QString {
522
  QFileInfo srcFileInfo(src);
5✔
523
  QFileInfo destFileInfo(dest);
5✔
524
  QString destFile;
5✔
525
  QString srcFileBaseName = srcFileInfo.fileName();
5✔
526

527
  if (srcFileInfo.isFile()) {
5✔
528
    if (destFileInfo.isFile()) {
4✔
529
      if (!force) {
2✔
530
#ifdef QT_DEBUG
531
        dbg() << "Destination file already exists";
532
#endif
533
        return QString();
534
      }
535
      destFile = dest;
1✔
536
    } else if (destFileInfo.isDir()) {
2✔
537
      destFile = QDir(dest).filePath(srcFileBaseName);
2✔
538
    } else {
539
      destFile = dest;
1✔
540
    }
541

542
    if (destFile.endsWith(".gpg", Qt::CaseInsensitive)) {
6✔
543
      destFile.chop(4);
3✔
544
    }
545
    destFile.append(".gpg");
3✔
546
  } else if (srcFileInfo.isDir()) {
1✔
547
    if (destFileInfo.isDir()) {
×
548
      destFile = QDir(dest).filePath(srcFileBaseName);
×
549
    } else if (destFileInfo.isFile()) {
×
550
#ifdef QT_DEBUG
551
      dbg() << "Destination is a file";
552
#endif
553
      return QString();
554
    } else {
555
      destFile = dest;
×
556
    }
557
  } else {
558
#ifdef QT_DEBUG
559
    dbg() << "Source file does not exist";
560
#endif
561
    return QString();
562
  }
563
  return destFile;
564
}
5✔
565

566
void ImitatePass::executeMoveGit(const QString &src, const QString &destFile,
×
567
                                 bool force) {
568
  QStringList args;
×
569
  args << "mv";
×
570
  if (force) {
×
571
    args << "-f";
×
572
  }
573
  args << pgit(src);
×
574
  args << pgit(destFile);
×
575
  executeGit(GIT_MOVE, args);
×
576

577
  QString relSrc = QDir(QtPassSettings::getPassStore()).relativeFilePath(src);
×
578
  relSrc.replace(Util::endsWithGpg(), "");
×
579
  QString relDest =
580
      QDir(QtPassSettings::getPassStore()).relativeFilePath(destFile);
×
581
  relDest.replace(Util::endsWithGpg(), "");
×
582
  QString message = QString("Moved for %1 to %2 using QtPass.");
×
583
  message = message.arg(relSrc, relDest);
×
584
  GitCommit("", message);
×
585
}
×
586

587
void ImitatePass::Move(const QString src, const QString dest,
×
588
                       const bool force) {
589
  transactionHelper trans(this, PASS_MOVE);
×
590
  QString destFile = resolveMoveDestination(src, dest, force);
×
591
  if (destFile.isEmpty()) {
×
592
    return;
593
  }
594

595
#ifdef QT_DEBUG
596
  dbg() << "Move Source: " << src;
597
  dbg() << "Move Destination: " << destFile;
598
#endif
599

600
  if (QtPassSettings::isUseGit()) {
×
601
    executeMoveGit(src, destFile, force);
×
602
  } else {
603
    QDir qDir;
×
604
    if (force) {
×
605
      qDir.remove(destFile);
×
606
    }
607
    qDir.rename(src, destFile);
×
608
  }
×
609
}
610

611
void ImitatePass::Copy(const QString src, const QString dest,
×
612
                       const bool force) {
613
  QFileInfo destFileInfo(dest);
×
614
  transactionHelper trans(this, PASS_COPY);
×
615
  if (QtPassSettings::isUseGit()) {
×
616
    QStringList args;
×
617
    args << "cp";
×
618
    if (force) {
×
619
      args << "-f";
×
620
    }
621
    args << pgit(src);
×
622
    args << pgit(dest);
×
623
    executeGit(GIT_COPY, args);
×
624

NEW
625
    QString message = QString("Copied from %1 to %2 using QtPass.");
×
626
    message = message.arg(src, dest);
×
627
    GitCommit("", message);
×
628
  } else {
629
    QDir qDir;
×
630
    if (force) {
×
631
      qDir.remove(dest);
×
632
    }
633
    QFile::copy(src, dest);
×
634
  }
×
635
  // reecrypt all files under the new folder
636
  if (destFileInfo.isDir()) {
×
637
    reencryptPath(destFileInfo.absoluteFilePath());
×
638
  } else if (destFileInfo.isFile()) {
×
639
    reencryptPath(destFileInfo.dir().path());
×
640
  }
641
}
×
642

643
/**
644
 * @brief ImitatePass::executeGpg easy wrapper for running gpg commands
645
 * @param args
646
 */
647
void ImitatePass::executeGpg(PROCESS id, const QStringList &args, QString input,
×
648
                             bool readStdout, bool readStderr) {
649
  executeWrapper(id, QtPassSettings::getGpgExecutable(), args, std::move(input),
×
650
                 readStdout, readStderr);
651
}
×
652
/**
653
 * @brief ImitatePass::executeGit easy wrapper for running git commands
654
 * @param args
655
 */
656
void ImitatePass::executeGit(PROCESS id, const QStringList &args, QString input,
×
657
                             bool readStdout, bool readStderr) {
658
  executeWrapper(id, QtPassSettings::getGitExecutable(), args, std::move(input),
×
659
                 readStdout, readStderr);
660
}
×
661

662
/**
663
 * @brief ImitatePass::finished this function is overloaded to ensure
664
 *                              identical behaviour to RealPass ie. only PASS_*
665
 *                              processes are visible inside Pass::finish, so
666
 *                              that interface-wise it all looks the same
667
 * @param id
668
 * @param exitCode
669
 * @param out
670
 * @param err
671
 */
672
void ImitatePass::finished(int id, int exitCode, const QString &out,
×
673
                           const QString &err) {
674
#ifdef QT_DEBUG
675
  dbg() << "Imitate Pass";
676
#endif
677
  static QString transactionOutput;
×
678
  PROCESS pid = transactionIsOver(static_cast<PROCESS>(id));
×
679
  transactionOutput.append(out);
×
680

681
  if (exitCode == 0) {
×
682
    if (pid == INVALID) {
×
683
      return;
684
    }
685
  } else {
686
    while (pid == INVALID) {
×
687
      id = exec.cancelNext();
×
688
      if (id == -1) {
×
689
        //  this is probably irrecoverable and shall not happen
690
#ifdef QT_DEBUG
691
        dbg() << "No such transaction!";
692
#endif
693
        return;
694
      }
695
      pid = transactionIsOver(static_cast<PROCESS>(id));
×
696
    }
697
  }
698
  Pass::finished(pid, exitCode, transactionOutput, err);
×
699
  transactionOutput.clear();
×
700
}
701

702
/**
703
 * @brief executeWrapper    overrided so that every execution is a transaction
704
 * @param id
705
 * @param app
706
 * @param args
707
 * @param input
708
 * @param readStdout
709
 * @param readStderr
710
 */
711
void ImitatePass::executeWrapper(PROCESS id, const QString &app,
×
712
                                 const QStringList &args, QString input,
713
                                 bool readStdout, bool readStderr) {
714
  transactionAdd(id);
×
715
  Pass::executeWrapper(id, app, args, input, readStdout, readStderr);
×
716
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc