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

IJHack / QtPass / 24592374028

18 Apr 2026 12:21AM UTC coverage: 22.91% (+1.0%) from 21.908%
24592374028

Pull #1037

github

web-flow
Merge 2b62d6d88 into 79d758a1a
Pull Request #1037: feat: implement pass grep content search (#109)

72 of 143 new or added lines in 5 files covered. (50.35%)

198 existing lines in 4 files now uncovered.

1296 of 5657 relevant lines covered (22.91%)

8.6 hits per line

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

0.0
/src/realpass.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "realpass.h"
4
#include "debughelper.h"
5
#include "qtpasssettings.h"
6
#include "util.h"
7

8
#include <QDir>
9
#include <QFileInfo>
10
#include <QRegularExpression>
11
#include <utility>
12

13
using Enums::GIT_INIT;
14
using Enums::GIT_PULL;
15
using Enums::GIT_PUSH;
16
using Enums::PASS_COPY;
17
using Enums::PASS_GREP;
18
using Enums::PASS_INIT;
19
using Enums::PASS_INSERT;
20
using Enums::PASS_MOVE;
21
using Enums::PASS_OTP_GENERATE;
22
using Enums::PASS_REMOVE;
23
using Enums::PASS_SHOW;
24

25
RealPass::RealPass() = default;
×
26

27
/**
28
 * @brief RealPass::GitInit pass git init wrapper
29
 */
30
void RealPass::GitInit() { executePass(GIT_INIT, {"git", "init"}); }
×
31

32
/**
33
 * @brief RealPass::GitInit pass git pull wrapper which blocks until process
34
 *                          finishes
35
 */
36
void RealPass::GitPull_b() {
×
37
  int result = Executor::executeBlocking(QtPassSettings::getPassExecutable(),
×
38
                                         {"git", "pull"});
39
  if (result != 0) {
40
#ifdef QT_DEBUG
41
    dbg() << "Git pull failed with code:" << result;
42
#endif
43
  }
44
}
×
45

46
/**
47
 * @brief RealPass::GitPull pass git pull wrapper
48
 */
49
void RealPass::GitPull() { executePass(GIT_PULL, {"git", "pull"}); }
×
50

51
/**
52
 * @brief RealPass::GitPush pass git push wrapper
53
 */
54
void RealPass::GitPush() { executePass(GIT_PUSH, {"git", "push"}); }
×
55

56
/**
57
 * @brief RealPass::Show pass show
58
 *
59
 * @param file      file to decrypt
60
 *
61
 * @return  if block is set, returns exit status of internal decryption
62
 * process
63
 *          otherwise returns QProcess::NormalExit
64
 */
65
void RealPass::Show(QString file) {
×
66
  executePass(PASS_SHOW, {"show", file}, "", true);
×
67
}
×
68

69
/**
70
 * @brief RealPass::OtpGenerate pass otp
71
 * @param file      file containing OTP uri
72
 */
73
void RealPass::OtpGenerate(QString file) {
×
74
  executePass(PASS_OTP_GENERATE, {"otp", file}, "", true);
×
75
}
×
76

77
/**
78
 * @brief RealPass::Insert pass insert
79
 */
80
void RealPass::Insert(QString file, QString newValue, bool overwrite) {
×
81
  QStringList args = {"insert", "-m"};
×
82
  if (overwrite) {
×
83
    args.append("-f");
×
84
  }
85
  args.append(file);
86
  executePass(PASS_INSERT, args, newValue);
×
87
}
×
88

89
/**
90
 * @brief RealPass::Remove pass remove wrapper
91
 */
92
void RealPass::Remove(QString file, bool isDir) {
×
93
  executePass(PASS_REMOVE, {"rm", (isDir ? "-rf" : "-f"), file});
×
94
}
×
95

96
/**
97
 * @brief RealPass::Init initialize pass repository
98
 *
99
 * @param path  Absolute path to new password-store
100
 * @param users list of users with ability to decrypt new password-store
101
 */
102
void RealPass::Init(QString path, const QList<UserInfo> &users) {
×
103
  // remove the passStore directory otherwise,
104
  // pass would create a passStore/passStore/dir
105
  // but you want passStore/dir
106
  QString dirWithoutPassdir =
107
      path.remove(0, QtPassSettings::getPassStore().size());
×
108
  QStringList args = {"init", "--path=" + dirWithoutPassdir};
×
109
  foreach (const UserInfo &user, users) {
×
110
    if (user.enabled) {
×
111
      args.append(user.key_id);
×
112
    }
113
  }
114
  executePass(PASS_INIT, args);
×
115
}
×
116

117
/**
118
 * @brief RealPass::Move move a file (or folder)
119
 * @param src source file or folder
120
 * @param dest destination file or folder
121
 * @param force overwrite
122
 */
123
void RealPass::Move(const QString src, const QString dest, const bool force) {
×
124
  QFileInfo srcFileInfo = QFileInfo(src);
×
125
  QFileInfo destFileInfo = QFileInfo(dest);
×
126

127
  // force mode?
128
  // pass uses always the force mode, when call from eg. QT. so we have to
129
  // check if this are to files and the user didnt want to move force
130
  if (!force && srcFileInfo.isFile() && destFileInfo.isFile()) {
×
131
    return;
132
  }
133

134
  QString passSrc = QDir(QtPassSettings::getPassStore())
×
135
                        .relativeFilePath(QDir(src).absolutePath());
×
136
  QString passDest = QDir(QtPassSettings::getPassStore())
×
137
                         .relativeFilePath(QDir(dest).absolutePath());
×
138

139
  // remove the .gpg because pass will not work
140
  if (srcFileInfo.isFile() && srcFileInfo.suffix() == "gpg") {
×
141
    passSrc.replace(Util::endsWithGpg(), "");
×
142
  }
143
  if (destFileInfo.isFile() && destFileInfo.suffix() == "gpg") {
×
144
    passDest.replace(Util::endsWithGpg(), "");
×
145
  }
146

147
  QStringList args;
×
148
  args << "mv";
×
149
  if (force) {
×
150
    args << "-f";
×
151
  }
152
  args << passSrc;
153
  args << passDest;
154
  executePass(PASS_MOVE, args);
×
155
}
×
156

157
/**
158
 * @brief RealPass::Copy copy a file (or folder)
159
 * @param src source file or folder
160
 * @param dest destination file or folder
161
 * @param force overwrite
162
 */
163
void RealPass::Copy(const QString src, const QString dest, const bool force) {
×
164
  QFileInfo srcFileInfo = QFileInfo(src);
×
165
  QFileInfo destFileInfo = QFileInfo(dest);
×
166
  // force mode?
167
  // pass uses always the force mode, when call from eg. QT. so we have to
168
  // check if this are to files and the user didnt want to move force
169
  if (!force && srcFileInfo.isFile() && destFileInfo.isFile()) {
×
170
    return;
171
  }
172

173
  QString passSrc = QDir(QtPassSettings::getPassStore())
×
174
                        .relativeFilePath(QDir(src).absolutePath());
×
175
  QString passDest = QDir(QtPassSettings::getPassStore())
×
176
                         .relativeFilePath(QDir(dest).absolutePath());
×
177

178
  // remove the .gpg because pass will not work
179
  if (srcFileInfo.isFile() && srcFileInfo.suffix() == "gpg") {
×
180
    passSrc.replace(Util::endsWithGpg(), "");
×
181
  }
182
  if (destFileInfo.isFile() && destFileInfo.suffix() == "gpg") {
×
183
    passDest.replace(Util::endsWithGpg(), "");
×
184
  }
185
  QStringList args;
×
186
  args << "cp";
×
187
  if (force) {
×
188
    args << "-f";
×
189
  }
190
  args << passSrc;
191
  args << passDest;
192
  executePass(PASS_COPY, args);
×
193
}
×
194

195
/**
196
 * @brief Search all password content via 'pass grep'.
197
 * @param pattern Search pattern.
198
 * @param caseInsensitive true for case-insensitive search.
199
 */
NEW
200
void RealPass::Grep(QString pattern, bool caseInsensitive) {
×
NEW
201
  QStringList args = {"grep"};
×
NEW
202
  if (caseInsensitive)
×
NEW
203
    args << "-i";
×
NEW
204
  args << "--" << pattern;
×
NEW
205
  executePass(PASS_GREP, args, QString(), true);
×
NEW
206
}
×
207

208
/**
209
 * @brief Wrapper for executing pass commands.
210
 * @param id Process identifier for this operation
211
 * @param args Command-line arguments for pass
212
 * @param input Input to pass to the process (typically empty)
213
 * @param readStdout Whether to capture standard output
214
 * @param readStderr Whether to capture standard error output
215
 */
216
void RealPass::executePass(PROCESS id, const QStringList &args, QString input,
×
217
                           bool readStdout, bool readStderr) {
218
  executeWrapper(id, QtPassSettings::getPassExecutable(), args,
×
219
                 std::move(input), readStdout, readStderr);
220
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc