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

IJHack / QtPass / 44265697413

18 Nov 2026 08:17AM UTC coverage: 96.28% (-0.1%) from 96.396%
44265697413

push

github

web-flow
Git commits take only their own paths; tool output stays plain and short (#2260)

* Git commits take only their own paths; tool output stays plain and short

- createBackupCommit() stages and commits the store only (`-- .` with -C
  the store): in a repository above it, a modified tracked file outside
  was committed and auto-pushed. The conflict check keeps its
  repository-wide status. Move and copy commit their own paths, not
  whatever else was staged (ANT-2026-P6R5B5PK).
- The first-run wizard, Settings and the key export show their boxes
  with PlainMessageBox: ProfileInit's note ends in git's stderr, which can
  quote a pushed .gitattributes value as markup and a link
  (ANT-2026-V7X4M2B6).
- PlainMessageBox shows at most 40 lines and 4000 characters: a box
  laying out git's whole error output froze the GUI
  (ANT-2026-J1OLDGTJ).
- repositoryPassClimbsTo() reads HEAD and a .git file with
  openRegularFile(): a link to a FIFO or a device blocked the open on the
  GUI thread when Settings opened (ANT-2026-0KZE41ZD).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Anne Jan Brouwer <brouwer@annejan.com>

* Names on one line in confirmations; git's own metadata links count

From the #2260 review:
- The re-encrypt, link-removal and overwrite questions put the quoted
  names on one line: a folder name with line feeds pushed the warning out
  of the box, which now shows 40 lines at most, and Yes still ran.
- repositoryPassClimbsTo() opens HEAD and a .git file following links
  but only to a regular file, without blocking (O_NONBLOCK, then fstat):
  git takes HEAD -> refs/heads/main and a .git link to a gitfile, which
  openRegularFile()'s O_NOFOLLOW refused, so the Settings warning about
  the repository pass commits in went missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Anne Jan Brouwer <brouwer@annejan.com>

* Message boxes: the rest of a cut message under Show Details

From the #2260 review:... (continued)

79 of 93 new or added lines in 8 files covered. (84.95%)

6 existing lines in 1 file now uncovered.

9110 of 9462 relevant lines covered (96.28%)

1291.19 hits per line

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

92.57
/src/storemodel.cpp
1
// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
/**
4
 * @file
5
 * @brief Implements StoreModel and the StoreDragItem stream operators; the
6
 *        drop validation lives in executeDropAction().
7
 */
8
#include "storemodel.h"
9
#include "pass.h"
10
#include "pathvalidator.h"
11
#include "plainmessagebox.h"
12
#include "qtpasslogging.h"
13
#include "util.h"
14
#include <QApplication>
15
#include <QDebug>
16
#include <QFileSystemModel>
17
#include <QMessageBox>
18
#include <QMimeData>
19
#include <QRegularExpression>
20
#include <QtGlobal>
21

22
auto operator<<(QDataStream &out, const StoreDragItem &item) -> QDataStream & {
16 ✔
23
  out << static_cast<quint8>(item.kind) << item.path;
16 ✔
24
  return out;
16 ✔
25
}
26

27
auto operator>>(QDataStream &in, StoreDragItem &item) -> QDataStream & {
23 ✔
28
  quint8 k;
29
  in >> k >> item.path;
23 ✔
30
  switch (k) {
23 ✔
31
  case static_cast<quint8>(StoreDragItem::ItemKind::Directory):
5 ✔
32
    item.kind = StoreDragItem::ItemKind::Directory;
5 ✔
33
    break;
5 ✔
34
  case static_cast<quint8>(StoreDragItem::ItemKind::File):
17 ✔
35
    item.kind = StoreDragItem::ItemKind::File;
17 ✔
36
    break;
17 ✔
37
  default:
1 ✔
38
    item.kind = StoreDragItem::ItemKind::Unknown;
1 ✔
39
    break;
1 ✔
40
  }
41
  return in;
23 ✔
42
}
43

44
// Filter approach via http://www.qtcentre.org/threads/46471-QTreeView-Filter
45
StoreModel::StoreModel() { fs = nullptr; }
230 ✔
46

47
void StoreModel::setPass(Pass *pass) { m_pass = pass; }
193 ✔
48

49
auto StoreModel::filterAcceptsRow(int sourceRow,
8,818 ✔
50
                                  const QModelIndex &sourceParent) const
51
    -> bool {
52
  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
8,818 ✔
53
  return showThis(index);
8,818 ✔
54
}
55

56
auto StoreModel::showThis(const QModelIndex &index) const -> bool {
13,884 ✔
57
  if (fs == nullptr) {
13,884 ✔
58
    return false;
59
  }
60
  const QString filePath = fs->filePath(index);
13,691 ✔
61
  QString path = QDir(store).relativeFilePath(filePath);
13,691 ✔
62
  // Only what lies in the current store. The file system model keeps the
63
  // rows of a store shown earlier (a profile switch only re-roots it), and
64
  // a search would otherwise match those, open one and save it encrypted
65
  // to this store's recipients. Folders above the store still lead there.
66
  const bool outside = path == QLatin1String("..") ||
27,382 ✔
67
                       path.startsWith(QLatin1String("../")) ||
27,382 ✔
68
                       QDir::isAbsolutePath(path);
69
  // A link inside the store is neither an entry nor a folder (SECURITY.md):
70
  // it is listed by its name, so it can be deleted, but never entered. A
71
  // planted `x -> .` was an endlessly expandable folder, and the search's
72
  // expandAll() loaded it level after level until memory ran out.
73
  const bool inside = !outside && path != QLatin1String(".");
13,691 ✔
74
  if (inside && Util::isUnderLink(filePath, store, false)) {
10,565 ✔
75
    return false;
76
  }
77
  const bool link = inside && Util::isLinkedFolder(filePath);
13,684 ✔
78
  if (!link && sourceModel()->rowCount(index) > 0) {
13,664 ✔
79
    for (int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
5,332 ✔
80
      const QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
5,065 ✔
81
      if (!childIndex.isValid()) {
82
        break;
83
      }
84
      if (showThis(childIndex)) {
5,065 ✔
85
        return true;
2,157 ✔
86
      }
87
    }
88
    return false;
267 ✔
89
  }
90
  if (outside || path.startsWith(".git")) {
22,234 ✔
91
    return false;
92
  }
93
  path.replace(Util::endsWithGpg(), "");
10,973 ✔
94
  return path.contains(filterRegularExpression());
10,973 ✔
95
}
96

97
auto StoreModel::isLinkInStore(const QModelIndex &proxyIndex) const -> bool {
2,669 ✔
98
  if (fs == nullptr || !proxyIndex.isValid()) {
2,669 ✔
99
    return false;
100
  }
101
  const QString filePath = fs->filePath(mapToSource(proxyIndex));
2,216 ✔
102
  const QString path = QDir(store).relativeFilePath(filePath);
2,216 ✔
103
  if (path == QLatin1String(".") || path == QLatin1String("..") ||
3,293 ✔
104
      path.startsWith(QLatin1String("../")) || QDir::isAbsolutePath(path)) {
4,364 ✔
105
    return false;
1,145 ✔
106
  }
107
  return Util::isLinkedFolder(filePath);
1,071 ✔
108
}
109

110
auto StoreModel::hasChildren(const QModelIndex &parent) const -> bool {
1,929 ✔
111
  return !isLinkInStore(parent) && QSortFilterProxyModel::hasChildren(parent);
1,929 ✔
112
}
113

114
auto StoreModel::canFetchMore(const QModelIndex &parent) const -> bool {
671 ✔
115
  return !isLinkInStore(parent) && QSortFilterProxyModel::canFetchMore(parent);
671 ✔
116
}
117

118
void StoreModel::fetchMore(const QModelIndex &parent) {
69 ✔
119
  if (!isLinkInStore(parent)) {
69 ✔
120
    QSortFilterProxyModel::fetchMore(parent);
68 ✔
121
  }
122
}
69 ✔
123

124
void StoreModel::setModelAndStore(QFileSystemModel *sourceModel,
224 ✔
125
                                  const QString &passStore) {
126
  setSourceModel(sourceModel);
224 ✔
127
  fs = sourceModel;
224 ✔
128
  store = passStore;
224 ✔
129
}
224 ✔
130

131
auto StoreModel::rootIndexFor(const QString &path) -> QModelIndex {
301 ✔
132
  if (fs == nullptr) {
301 ✔
133
    return {};
1 ✔
134
  }
135
  return mapFromSource(fs->setRootPath(QDir::cleanPath(path)));
600 ✔
136
}
137

138
void StoreModel::setStore(const QString &passStore) {
14 ✔
139
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
140
  // The Direction-scoped endFilterChange() overload needs Qt 6.10.
141
  beginFilterChange();
142
  store = passStore;
143
  endFilterChange(QSortFilterProxyModel::Direction::Rows);
144
#else
145
  store = passStore;
14 ✔
146
  invalidateFilter();
14 ✔
147
#endif
148
}
14 ✔
149

150
auto StoreModel::data(const QModelIndex &index, int role) const -> QVariant {
36,085 ✔
151
  if (!index.isValid()) {
152
    return {};
153
  }
154

155
  QVariant initial_value;
156
  initial_value = QSortFilterProxyModel::data(index, role);
36,084 ✔
157

158
  if (role == Qt::DisplayRole) {
36,084 ✔
159
    QString name = initial_value.toString();
4,751 ✔
160
    name.replace(Util::endsWithGpg(), "");
4,751 ✔
161
    initial_value.setValue(name);
4,751 ✔
162
  }
163

164
  return initial_value;
165
}
36,084 ✔
166

167
auto StoreModel::supportedDropActions() const -> Qt::DropActions {
1 ✔
168
  return Qt::CopyAction | Qt::MoveAction;
1 ✔
169
}
170

171
auto StoreModel::supportedDragActions() const -> Qt::DropActions {
1 ✔
172
  return Qt::CopyAction | Qt::MoveAction;
1 ✔
173
}
174

175
auto StoreModel::flags(const QModelIndex &index) const -> Qt::ItemFlags {
14,705 ✔
176
  Qt::ItemFlags defaultFlags = QSortFilterProxyModel::flags(index);
14,705 ✔
177

178
  if (index.isValid()) {
179
    return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
180
  }
181
  return Qt::ItemIsDropEnabled | defaultFlags;
1 ✔
182
}
183

184
auto StoreModel::mimeTypes() const -> QStringList {
1 ✔
185
  QStringList types;
1 ✔
186
  types << kStoreDragMimeType;
×
187
  return types;
1 ✔
188
}
189

190
auto StoreModel::mimeData(const QModelIndexList &indexes) const -> QMimeData * {
1 ✔
191
  StoreDragItem info;
1 ✔
192

193
  if (indexes.isEmpty())
1 ✔
194
    return nullptr;
195
  QByteArray encodedData;
1 ✔
196
  // only use the first, otherwise we should enable multiselection
197
  QModelIndex index = indexes.at(0);
1 ✔
198
  if (index.isValid()) {
199
    QModelIndex useIndex = mapToSource(index);
1 ✔
200
    const QFileInfo fileInfo = fs->fileInfo(useIndex);
1 ✔
201

202
    if (fileInfo.isDir()) {
1 ✔
203
      info.kind = StoreDragItem::ItemKind::Directory;
×
204
    } else if (fileInfo.isFile()) {
1 ✔
205
      info.kind = StoreDragItem::ItemKind::File;
1 ✔
206
    }
207
    info.path = fileInfo.absoluteFilePath();
1 ✔
208
    QDataStream stream(&encodedData, QIODevice::WriteOnly);
1 ✔
209
    stream << info;
1 ✔
210
  }
1 ✔
211

212
  auto *mimeData = new QMimeData();
1 ✔
213
  mimeData->setData(kStoreDragMimeType, encodedData);
2 ✔
214
  return mimeData;
215
}
216

217
auto StoreModel::canDropMimeData(const QMimeData *data, Qt::DropAction action,
16 ✔
218
                                 int row, int column,
219
                                 const QModelIndex &parent) const -> bool {
220
  qCDebug(lcQtPass) << "canDropMimeData" << action << row;
16 ✔
221

222
  const auto parsed = parseDropData(data);
16 ✔
223
  if (!parsed) {
16 ✔
224
    return false;
225
  }
226
  const StoreDragItem &info = *parsed;
227

228
  QModelIndex useIndex =
229
      this->index(parent.row(), parent.column(), parent.parent());
13 ✔
230

231
  if (column > 0) {
13 ✔
232
    return false;
233
  }
234

235
  using IK = StoreDragItem::ItemKind;
236
  // you can drop a folder on a folder
237
  if (fs->fileInfo(mapToSource(useIndex)).isDir() &&
24 ✔
238
      info.kind == IK::Directory) {
10 ✔
239
    return true;
240
  }
241
  // you can drop a file on a folder
242
  if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.kind == IK::File) {
12 ✔
243
    return true;
244
  }
245
  // you can drop a file on a file
246
  if (fs->fileInfo(mapToSource(useIndex)).isFile() && info.kind == IK::File) {
3 ✔
247
    return true;
248
  }
249

250
  return false;
251
}
252

253
auto StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
8 ✔
254
                              int row, int column, const QModelIndex &parent)
255
    -> bool {
256
  if (!canDropMimeData(data, action, row, column, parent)) {
8 ✔
257
    return false;
258
  }
259

260
  if (action == Qt::IgnoreAction) {
8 ✔
261
    return true;
262
  }
263

264
  if (action != Qt::MoveAction && action != Qt::CopyAction) {
7 ✔
265
    return false;
266
  }
267

268
  const auto info = parseDropData(data);
7 ✔
269
  if (!info) {
7 ✔
270
    return false;
271
  }
272

273
  return executeDropAction(*info, action, parent);
7 ✔
274
}
275

276
auto StoreModel::parseDropData(const QMimeData *data)
23 ✔
277
    -> std::optional<StoreDragItem> {
278
  if (data == nullptr || !data->hasFormat(kStoreDragMimeType)) {
45 ✔
279
    return std::nullopt;
2 ✔
280
  }
281
  QByteArray encodedData = data->data(kStoreDragMimeType);
42 ✔
282
  if (encodedData.isEmpty()) {
21 ✔
283
    return std::nullopt;
1 ✔
284
  }
285
  QDataStream stream(&encodedData, QIODevice::ReadOnly);
20 ✔
286
  StoreDragItem info;
20 ✔
287
  stream >> info;
20 ✔
288
  if (stream.status() != QDataStream::Ok) {
20 ✔
289
    return std::nullopt;
×
290
  }
291
  return info;
292
}
20 ✔
293

294
auto StoreModel::executeDropAction(const StoreDragItem &info,
7 ✔
295
                                   Qt::DropAction action,
296
                                   const QModelIndex &parent) -> bool {
297
  QModelIndex destIndex =
298
      this->index(parent.row(), parent.column(), parent.parent());
7 ✔
299
  QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex));
7 ✔
300
  QFileInfo srcFileInfo = QFileInfo(info.path);
7 ✔
301

302
  QString cleanedSrc = QDir::cleanPath(srcFileInfo.absoluteFilePath());
7 ✔
303
  QString cleanedDest = QDir::cleanPath(destFileinfo.absoluteFilePath());
7 ✔
304

305
  // Drop data could be crafted: both endpoints must resolve inside the store
306
  // after symlink resolution (e.g. no in-store symlink pointing at /etc).
307
  if (!PathValidator::isPathInStore(store, cleanedSrc) ||
11 ✔
308
      !PathValidator::isPathInStore(store, cleanedDest)) {
4 ✔
309
    qCWarning(lcQtPass)
6 ✔
310
        << "executeDropAction: rejecting drop that escapes the store"
3 ✔
311
        << "(src=" << cleanedSrc << "dest=" << cleanedDest << ")";
3 ✔
312
    return false;
3 ✔
313
  }
314

315
  switch (info.kind) {
4 ✔
316
  case StoreDragItem::ItemKind::Directory: {
1 ✔
317
    // Dropping a folder onto a folder: move/copy it *into* the target.
318
    if (!destFileinfo.isDir()) {
1 ✔
319
      return false;
320
    }
321
    const QString destDir =
322
        QDir::cleanPath(QDir(cleanedDest).filePath(srcFileInfo.fileName()));
2 ✔
323
    return performDrop(cleanedSrc, destDir, action, false);
1 ✔
324
  }
325
  case StoreDragItem::ItemKind::File:
3 ✔
326
    // File onto a folder drops into it (no clash); file onto an existing
327
    // file asks before overwriting.
328
    if (destFileinfo.isDir()) {
3 ✔
329
      return performDrop(cleanedSrc, cleanedDest, action, false);
3 ✔
330
    }
NEW
331
    return performDrop(cleanedSrc, cleanedDest, action,
×
NEW
332
                       PlainMessageBox::askYes(
×
333
                           qobject_cast<QWidget *>(QObject::parent()),
NEW
334
                           tr("Force overwrite?"),
×
NEW
335
                           tr("overwrite %1 with %2?")
×
NEW
336
                               .arg(Util::displayable(cleanedDest, false),
×
NEW
337
                                    Util::displayable(cleanedSrc, false))));
×
338
  default:
×
339
    qCWarning(lcQtPass)
×
340
        << "executeDropAction: unexpected ItemKind, ignoring drop";
×
341
    return false;
×
342
  }
343
}
7 ✔
344

345
auto StoreModel::performDrop(const QString &cleanedSrc,
4 ✔
346
                             const QString &cleanedDest, Qt::DropAction action,
347
                             bool force) -> bool {
348
  if (!m_pass) {
4 ✔
349
    return false;
350
  }
351
  if (action == Qt::MoveAction) {
3 ✔
352
    m_pass->Move(cleanedSrc, cleanedDest, force);
6 ✔
353
  } else if (action == Qt::CopyAction) {
1 ✔
354
    m_pass->Copy(cleanedSrc, cleanedDest, force);
3 ✔
355
  }
356
  return true;
357
}
358

359
auto StoreModel::lessThan(const QModelIndex &source_left,
17,252 ✔
360
                          const QModelIndex &source_right) const -> bool {
361
/* matches logic in QFileSystemModelSorter::compareNodes() */
362
#ifndef Q_OS_MAC
363
  if (fs && (source_left.column() == 0 || source_left.column() == 1)) {
17,252 ✔
364
    bool leftD = fs->isDir(source_left);
17,252 ✔
365
    bool rightD = fs->isDir(source_right);
17,252 ✔
366

367
    if (leftD ^ rightD) {
17,252 ✔
368
      return leftD;
369
    }
370
  }
371
#endif
372

373
  return QSortFilterProxyModel::lessThan(source_left, source_right);
14,693 ✔
374
}
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