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

IJHack / QtPass / 23822318756

31 Mar 2026 10:25PM UTC coverage: 19.722% (-0.1%) from 19.849%
23822318756

push

github

web-flow
refactor: rename checkConfig to configIsValid and fix related issues (#873)

* refactor: rename checkConfig to configIsValid and fix related issues

- Fix QDir::exists() for directory paths (was using QFile incorrectly)
- Simplify PATH delimiter handling using QDir::separator()
- Rename checkConfig() -> configIsValid() with inverted logic
- Update all callers to use !configIsValid() instead
- Add clear documentation explaining the return value

Fixes CodeRabbit AI findings.

* fix: rename checkConfig to configIsValid in tests

Update test to match renamed function.

4 of 14 new or added lines in 4 files covered. (28.57%)

994 of 5040 relevant lines covered (19.72%)

7.95 hits per line

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

87.5
/src/util.cpp
1
// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "util.h"
4
#include <QDir>
5
#include <QFileInfo>
6
#ifdef Q_OS_WIN
7
#include <windows.h>
8
#else
9
#include <sys/time.h>
10
#endif
11
#include "qtpasssettings.h"
12

13
#ifdef QT_DEBUG
14
#include "debughelper.h"
15
#endif
16

17
QProcessEnvironment Util::_env;
18
bool Util::_envInitialised = false;
19

20
void Util::initialiseEnvironment() {
14✔
21
  if (!_envInitialised) {
14✔
22
    _env = QProcessEnvironment::systemEnvironment();
1✔
23
#ifdef __APPLE__
24
    QString path = _env.value("PATH");
25
    if (!path.contains("/usr/local/MacGPG2/bin") &&
26
        QDir("/usr/local/MacGPG2/bin").exists())
27
      path += ":/usr/local/MacGPG2/bin";
28
    if (!path.contains("/usr/local/bin"))
29
      path += ":/usr/local/bin";
30
    _env.insert("PATH", path);
31
#endif
32
#ifdef Q_OS_WIN
33
    QString path = _env.value("PATH");
34
    if (!path.contains("C:\\Program Files\\WinGPG\\x86") &&
35
        QDir("C:\\Program Files\\WinGPG\\x86").exists())
36
      path += ";C:\\Program Files\\WinGPG\\x86";
37
    if (!path.contains("C:\\Program Files\\GnuPG\\bin") &&
38
        QDir("C:\\Program Files\\GnuPG\\bin").exists())
39
      path += ";C:\\Program Files\\GnuPG\\bin";
40
    _env.insert("PATH", path);
41
#endif
42
#ifdef QT_DEBUG
43
    dbg() << _env.value("PATH");
44
#endif
45
    _envInitialised = true;
1✔
46
  }
47
}
14✔
48

49
auto Util::findPasswordStore() -> QString {
2✔
50
  QString path;
2✔
51
  initialiseEnvironment();
2✔
52
  if (_env.contains("PASSWORD_STORE_DIR")) {
4✔
53
    path = _env.value("PASSWORD_STORE_DIR");
×
54
  } else {
55
#ifdef Q_OS_WIN
56
    path = QDir::homePath() + QDir::separator() + "password-store" +
57
           QDir::separator();
58
#else
59
    path = QDir::homePath() + QDir::separator() + ".password-store" +
4✔
60
           QDir::separator();
61
#endif
62
  }
63
  return Util::normalizeFolderPath(path);
4✔
64
}
65

66
auto Util::normalizeFolderPath(QString path) -> QString {
11✔
67
  if (!path.endsWith("/") && !path.endsWith(QDir::separator())) {
22✔
68
    path += QDir::separator();
6✔
69
  }
70
  return QDir::toNativeSeparators(path);
11✔
71
}
72

73
auto Util::findBinaryInPath(QString binary) -> QString {
12✔
74
  initialiseEnvironment();
12✔
75

76
  QString ret;
12✔
77

78
  binary.prepend(QDir::separator());
12✔
79

80
  if (_env.contains("PATH")) {
24✔
81
    QString path = _env.value("PATH");
24✔
82
    const QChar delimiter = QDir::separator() == '\\' ? ';' : ':';
83
    QStringList entries = path.split(delimiter);
12✔
84

85
    for (const QString &entryConst : entries) {
192✔
86
      QString fullPath = entryConst + binary;
178✔
87
      QFileInfo qfi(fullPath);
178✔
88
#ifdef Q_OS_WIN
89
      if (!qfi.exists()) {
90
        QString fullPathExe = fullPath + ".exe";
91
        qfi = QFileInfo(fullPathExe);
92
      }
93

94
#endif
95
      if (!qfi.isExecutable()) {
178✔
96
        continue;
97
      }
98

99
      ret = qfi.absoluteFilePath();
10✔
100
      break;
101
    }
178✔
102
  }
103
#ifdef Q_OS_WIN
104
  if (ret.isEmpty()) {
105
    binary.remove(0, 1);
106
    binary.prepend("wsl ");
107
    QString out, err;
108
    if (Executor::executeBlocking(binary, {"--version"}, &out, &err) == 0 &&
109
        !out.isEmpty() && err.isEmpty())
110
      ret = binary;
111
  }
112
#endif
113

114
  return ret;
12✔
115
}
116

117
auto Util::configIsValid() -> bool {
1✔
118
  const QString configFilePath =
119
      QDir(QtPassSettings::getPassStore()).filePath(".gpg-id");
3✔
120
  if (!QFile(configFilePath).exists()) {
1✔
121
    return false;
122
  }
123

NEW
124
  const QString executable = QtPassSettings::isUsePass()
×
NEW
125
                                 ? QtPassSettings::getPassExecutable()
×
NEW
126
                                 : QtPassSettings::getGpgExecutable();
×
127

NEW
128
  if (executable.startsWith("wsl ")) {
×
129
    return true;
130
  }
NEW
131
  return QFile(executable).exists();
×
132
}
133

134
auto Util::getDir(const QModelIndex &index, bool forPass,
3✔
135
                  const QFileSystemModel &model, const StoreModel &storeModel)
136
    -> QString {
137
  QString abspath =
138
      QDir(QtPassSettings::getPassStore()).absolutePath() + QDir::separator();
9✔
139
  if (!index.isValid()) {
140
    return forPass ? "" : abspath;
2✔
141
  }
142
  QFileInfo info = model.fileInfo(storeModel.mapToSource(index));
1✔
143
  QString filePath =
144
      (info.isFile() ? info.absolutePath() : info.absoluteFilePath());
1✔
145
  if (forPass) {
1✔
146
    filePath = QDir(abspath).relativeFilePath(filePath);
×
147
  }
148
  filePath += QDir::separator();
1✔
149
  return filePath;
150
}
1✔
151

152
auto Util::endsWithGpg() -> const QRegularExpression & {
22✔
153
  static const QRegularExpression expr{"\\.gpg$"};
22✔
154
  return expr;
22✔
155
}
156

157
auto Util::protocolRegex() -> const QRegularExpression & {
3✔
158
  static const QRegularExpression regex{
159
      "((?:https?|ftp|ssh|sftp|ftps|webdav|webdavs)://[^\" <>\\)\\]\\[]+)"};
3✔
160
  return regex;
3✔
161
}
162

163
auto Util::newLinesRegex() -> const QRegularExpression & {
2✔
164
  static const QRegularExpression regex{"[\r\n]"};
2✔
165
  return regex;
2✔
166
}
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