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

IJHack / QtPass / 43482519769

13 Nov 2026 06:25PM UTC coverage: 68.466% (+0.05%) from 68.419%
43482519769

push

github

web-flow
coverage: let lcov ignore inconsistent data on system headers (#2138)

lcov 2.x on the CI runner (gcc 15 headers) fails the coverage job with
"lcov: ERROR: (inconsistent) ...: function ... is not hit but line ... has
a non-zero hit count" on files outside the project (e.g. /usr/include/c++/15
and Qt headers), aborting lcov_prepare before coverage of src/ is produced.

The captures already pass "--ignore-errors unused"; add "inconsistent" the
same way. Only the consistency check on data filtered out anyway (-e src/*)
is bypassed; src/ coverage is unchanged. Backport of #2136.

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

5276 of 7706 relevant lines covered (68.47%)

72.38 hits per line

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

85.06
/src/storemodel.cpp
1
// SPDX-FileCopyrightText: 2014 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
#include "storemodel.h"
4
#include "pass.h"
5
#include "pathvalidator.h"
6
#include "util.h"
7
#include <QApplication>
8
#include <QDebug>
9
#include <QFileSystemModel>
10
#include <QMessageBox>
11
#include <QMimeData>
12
#include <QRegularExpression>
13
#include <QtGlobal>
14

15
auto operator<<(
11 ✔
16
    QDataStream &out,
17
    const dragAndDropInfoPasswordStore &dragAndDropInfoPasswordStore)
18
    -> QDataStream & {
19
  out << static_cast<quint8>(dragAndDropInfoPasswordStore.kind)
11 ✔
20
      << dragAndDropInfoPasswordStore.path;
11 ✔
21
  return out;
11 ✔
22
}
23

24
auto operator>>(QDataStream &in,
14 ✔
25
                dragAndDropInfoPasswordStore &dragAndDropInfoPasswordStore)
26
    -> QDataStream & {
27
  quint8 k;
28
  in >> k >> dragAndDropInfoPasswordStore.path;
14 ✔
29
  switch (k) {
14 ✔
30
  case static_cast<quint8>(dragAndDropInfoPasswordStore::ItemKind::Directory):
3 ✔
31
    dragAndDropInfoPasswordStore.kind =
3 ✔
32
        dragAndDropInfoPasswordStore::ItemKind::Directory;
33
    break;
3 ✔
34
  case static_cast<quint8>(dragAndDropInfoPasswordStore::ItemKind::File):
10 ✔
35
    dragAndDropInfoPasswordStore.kind =
10 ✔
36
        dragAndDropInfoPasswordStore::ItemKind::File;
37
    break;
10 ✔
38
  default:
1 ✔
39
    dragAndDropInfoPasswordStore.kind =
1 ✔
40
        dragAndDropInfoPasswordStore::ItemKind::Unknown;
41
    break;
1 ✔
42
  }
43
  return in;
14 ✔
44
}
45

46
/**
47
 * @brief StoreModel::StoreModel
48
 * SubClass of QSortFilterProxyModel via
49
 * http://www.qtcentre.org/threads/46471-QTreeView-Filter
50
 */
51
StoreModel::StoreModel() { fs = nullptr; }
60 ✔
52

53
void StoreModel::setPass(Pass *pass) { m_pass = pass; }
28 ✔
54

55
/**
56
 * @brief StoreModel::filterAcceptsRow should row be shown, wrapper for
57
 * StoreModel::showThis method.
58
 * @param sourceRow
59
 * @param sourceParent
60
 * @return
61
 */
62
auto StoreModel::filterAcceptsRow(int sourceRow,
198 ✔
63
                                  const QModelIndex &sourceParent) const
64
    -> bool {
65
  QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
198 ✔
66
  return showThis(index);
198 ✔
67
}
68

69
/**
70
 * @brief StoreModel::showThis should a row be shown, based on our search
71
 * criteria.
72
 * @param index
73
 * @return
74
 */
75
auto StoreModel::showThis(const QModelIndex &index) const -> bool {
427 ✔
76
  bool retVal = false;
77
  if (fs == nullptr) {
427 ✔
78
    return retVal;
79
  }
80
  // Gives you the info for number of children with a parent
81
  if (sourceModel()->rowCount(index) > 0) {
426 ✔
82
    for (int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
228 ✔
83
      QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
228 ✔
84
      if (!childIndex.isValid()) {
85
        break;
86
      }
87
      retVal = showThis(childIndex);
228 ✔
88
      if (retVal) {
228 ✔
89
        break;
90
      }
91
    }
92
  } else {
93
    QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
198 ✔
94
    QString path = fs->filePath(useIndex);
198 ✔
95
    path = QDir(store).relativeFilePath(path);
396 ✔
96
    if (path.startsWith(".git")) {
396 ✔
97
      return false;
98
    }
99
    path.replace(Util::endsWithGpg(), "");
197 ✔
100
    retVal = path.contains(filterRegularExpression());
197 ✔
101
  }
102
  return retVal;
103
}
104

105
/**
106
 * @brief StoreModel::setModelAndStore update the source model and store.
107
 * @param sourceModel
108
 * @param passStore
109
 */
110
void StoreModel::setModelAndStore(QFileSystemModel *sourceModel,
54 ✔
111
                                  const QString &passStore) {
112
  setSourceModel(sourceModel);
54 ✔
113
  fs = sourceModel;
54 ✔
114
  store = passStore;
54 ✔
115
}
54 ✔
116

117
auto StoreModel::rootIndexFor(const QString &path) -> QModelIndex {
5 ✔
118
  if (fs == nullptr) {
5 ✔
119
    return {};
1 ✔
120
  }
121
  return mapFromSource(fs->setRootPath(QDir::cleanPath(path)));
8 ✔
122
}
123

124
void StoreModel::setStore(const QString &passStore) {
4 ✔
125
#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 0)
126
  // beginFilterChange() is available since Qt 6.9, but the Direction-scoped
127
  // endFilterChange(QSortFilterProxyModel::Direction) overload is only
128
  // available since Qt 6.10, which is the preferred API for scoped and more
129
  // efficient filter updates.
130
  beginFilterChange();
131
  store = passStore;
132
  endFilterChange(QSortFilterProxyModel::Direction::Rows);
133
#else
134
  // Direction-scoped filter changes are unavailable before Qt 6.10, so older
135
  // Qt versions must manually invalidate filters. We update the store and
136
  // manually invalidate the filter as a compatibility path.
137
  store = passStore;
4 ✔
138
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
139
  QSortFilterProxyModel::invalidateFilter();
4 ✔
140
#else
141
  invalidateFilter();
142
#endif
143
#endif
144
}
4 ✔
145

146
/**
147
 * @brief StoreModel::data don't show the .gpg at the end of a file.
148
 * @param index
149
 * @param role
150
 * @return
151
 */
152
auto StoreModel::data(const QModelIndex &index, int role) const -> QVariant {
120 ✔
153
  if (!index.isValid()) {
154
    return {};
155
  }
156

157
  QVariant initial_value;
158
  initial_value = QSortFilterProxyModel::data(index, role);
119 ✔
159

160
  if (role == Qt::DisplayRole) {
119 ✔
161
    QString name = initial_value.toString();
24 ✔
162
    name.replace(Util::endsWithGpg(), "");
24 ✔
163
    initial_value.setValue(name);
24 ✔
164
  }
165

166
  return initial_value;
167
}
119 ✔
168

169
/**
170
 * @brief StoreModel::supportedDropActions enable drop.
171
 * @return
172
 */
173
auto StoreModel::supportedDropActions() const -> Qt::DropActions {
1 ✔
174
  return Qt::CopyAction | Qt::MoveAction;
1 ✔
175
}
176

177
/**
178
 * @brief StoreModel::supportedDragActions enable drag.
179
 * @return
180
 */
181
auto StoreModel::supportedDragActions() const -> Qt::DropActions {
1 ✔
182
  return Qt::CopyAction | Qt::MoveAction;
1 ✔
183
}
184

185
/**
186
 * @brief StoreModel::flags
187
 * @param index
188
 * @return
189
 */
190
auto StoreModel::flags(const QModelIndex &index) const -> Qt::ItemFlags {
80 ✔
191
  Qt::ItemFlags defaultFlags = QSortFilterProxyModel::flags(index);
80 ✔
192

193
  if (index.isValid()) {
194
    return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
195
  }
196
  return Qt::ItemIsDropEnabled | defaultFlags;
1 ✔
197
}
198

199
/**
200
 * @brief StoreModel::mimeTypes
201
 * @return
202
 */
203
auto StoreModel::mimeTypes() const -> QStringList {
1 ✔
204
  QStringList types;
1 ✔
205
  types << "application/vnd.qtpass.dragAndDropInfoPasswordStore";
1 ✔
206
  return types;
1 ✔
207
}
208

209
/**
210
 * @brief StoreModel::mimeData
211
 * @param indexes
212
 * @return
213
 */
214
auto StoreModel::mimeData(const QModelIndexList &indexes) const -> QMimeData * {
1 ✔
215
  dragAndDropInfoPasswordStore info;
1 ✔
216

217
  if (indexes.isEmpty())
1 ✔
218
    return nullptr;
219
  QByteArray encodedData;
1 ✔
220
  // only use the first, otherwise we should enable multiselection
221
  QModelIndex index = indexes.at(0);
1 ✔
222
  if (index.isValid()) {
223
    QModelIndex useIndex = mapToSource(index);
1 ✔
224
    const QFileInfo fileInfo = fs->fileInfo(useIndex);
1 ✔
225

226
    if (fileInfo.isDir()) {
1 ✔
227
      info.kind = dragAndDropInfoPasswordStore::ItemKind::Directory;
×
228
    } else if (fileInfo.isFile()) {
1 ✔
229
      info.kind = dragAndDropInfoPasswordStore::ItemKind::File;
1 ✔
230
    }
231
    info.path = fileInfo.absoluteFilePath();
1 ✔
232
    QDataStream stream(&encodedData, QIODevice::WriteOnly);
1 ✔
233
    stream << info;
1 ✔
234
  }
1 ✔
235

236
  auto *mimeData = new QMimeData();
1 ✔
237
  mimeData->setData("application/vnd.qtpass.dragAndDropInfoPasswordStore",
2 ✔
238
                    encodedData);
239
  return mimeData;
240
}
241

242
/**
243
 * @brief StoreModel::canDropMimeData
244
 * @param data
245
 * @param action
246
 * @param row
247
 * @param column
248
 * @param parent
249
 * @return
250
 */
251
auto StoreModel::canDropMimeData(const QMimeData *data, Qt::DropAction action,
11 ✔
252
                                 int row, int column,
253
                                 const QModelIndex &parent) const -> bool {
254
#ifdef QT_DEBUG
255
  qDebug() << action << row;
256
#else
257
  Q_UNUSED(action)
258
  Q_UNUSED(row)
259
#endif
260

261
  if (data == nullptr ||
21 ✔
262
      !data->hasFormat("application/vnd.qtpass.dragAndDropInfoPasswordStore")) {
21 ✔
263
    return false;
264
  }
265

266
  QByteArray encodedData =
267
      data->data("application/vnd.qtpass.dragAndDropInfoPasswordStore");
18 ✔
268
  if (encodedData.isEmpty()) {
9 ✔
269
    return false;
270
  }
271
  QDataStream stream(&encodedData, QIODevice::ReadOnly);
8 ✔
272
  dragAndDropInfoPasswordStore info;
8 ✔
273
  stream >> info;
8 ✔
274
  if (stream.status() != QDataStream::Ok) {
8 ✔
275
    return false;
276
  }
277

278
  QModelIndex useIndex =
279
      this->index(parent.row(), parent.column(), parent.parent());
8 ✔
280

281
  if (column > 0) {
8 ✔
282
    return false;
283
  }
284

285
  using IK = dragAndDropInfoPasswordStore::ItemKind;
286
  // you can drop a folder on a folder
287
  if (fs->fileInfo(mapToSource(useIndex)).isDir() &&
14 ✔
288
      info.kind == IK::Directory) {
5 ✔
289
    return true;
290
  }
291
  // you can drop a file on a folder
292
  if (fs->fileInfo(mapToSource(useIndex)).isDir() && info.kind == IK::File) {
8 ✔
293
    return true;
294
  }
295
  // you can drop a file on a file
296
  if (fs->fileInfo(mapToSource(useIndex)).isFile() && info.kind == IK::File) {
3 ✔
297
    return true;
298
  }
299

300
  return false;
301
}
8 ✔
302

303
/**
304
 * @brief StoreModel::dropMimeData
305
 * @param data
306
 * @param action
307
 * @param row
308
 * @param column
309
 * @param parent
310
 * @return
311
 */
312
auto StoreModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
3 ✔
313
                              int row, int column, const QModelIndex &parent)
314
    -> bool {
315
  if (!canDropMimeData(data, action, row, column, parent)) {
3 ✔
316
    return false;
317
  }
318

319
  if (action == Qt::IgnoreAction) {
3 ✔
320
    return true;
321
  }
322

323
  if (action != Qt::MoveAction && action != Qt::CopyAction) {
3 ✔
324
    return false;
325
  }
326

327
  dragAndDropInfoPasswordStore info;
3 ✔
328
  if (!parseDropData(data, &info)) {
3 ✔
329
    return false;
330
  }
331

332
  return executeDropAction(info, action, parent);
3 ✔
333
}
334

335
auto StoreModel::parseDropData(const QMimeData *data,
3 ✔
336
                               dragAndDropInfoPasswordStore *outInfo) -> bool {
337
  QByteArray encodedData =
338
      data->data("application/vnd.qtpass.dragAndDropInfoPasswordStore");
6 ✔
339
  if (encodedData.isEmpty()) {
3 ✔
340
    return false;
341
  }
342

343
  QDataStream stream(&encodedData, QIODevice::ReadOnly);
3 ✔
344
  dragAndDropInfoPasswordStore info;
3 ✔
345
  stream >> info;
3 ✔
346
  if (stream.status() != QDataStream::Ok) {
3 ✔
347
    return false;
348
  }
349

350
  *outInfo = info;
351
  return true;
3 ✔
352
}
3 ✔
353

354
auto StoreModel::executeDropAction(const dragAndDropInfoPasswordStore &info,
3 ✔
355
                                   Qt::DropAction action,
356
                                   const QModelIndex &parent) -> bool {
357
  QModelIndex destIndex =
358
      this->index(parent.row(), parent.column(), parent.parent());
3 ✔
359
  QFileInfo destFileinfo = fs->fileInfo(mapToSource(destIndex));
3 ✔
360
  QFileInfo srcFileInfo = QFileInfo(info.path);
3 ✔
361

362
  QString cleanedSrc = QDir::cleanPath(srcFileInfo.absoluteFilePath());
3 ✔
363
  QString cleanedDest = QDir::cleanPath(destFileinfo.absoluteFilePath());
3 ✔
364

365
  // Both endpoints must resolve inside the password store after symlink
366
  // resolution. Drop data is encoded by the dragged item but could be
367
  // crafted; canonical-path checks stop drops that would move/copy outside
368
  // the store or follow a symlink out (e.g. a symlink within the store
369
  // pointing at /etc).
370
  if (!PathValidator::isPathInStore(store, cleanedSrc) ||
3 ✔
371
      !PathValidator::isPathInStore(store, cleanedDest)) {
×
372
    qWarning() << "executeDropAction: rejecting drop that escapes the store"
6 ✔
373
               << "(src=" << cleanedSrc << "dest=" << cleanedDest << ")";
3 ✔
374
    return false;
3 ✔
375
  }
376

377
  switch (info.kind) {
×
378
  case dragAndDropInfoPasswordStore::ItemKind::Directory: {
×
379
    // Dropping a folder onto a folder: move/copy it *into* the target.
380
    if (!destFileinfo.isDir()) {
×
381
      return false;
382
    }
383
    const QString destDir =
384
        QDir::cleanPath(QDir(cleanedDest).filePath(srcFileInfo.fileName()));
×
385
    return performDrop(cleanedSrc, destDir, action, false);
×
386
  }
387
  case dragAndDropInfoPasswordStore::ItemKind::File:
×
388
    // File onto a folder drops into it (no clash); file onto an existing
389
    // file asks before overwriting.
390
    if (destFileinfo.isDir()) {
×
391
      return performDrop(cleanedSrc, cleanedDest, action, false);
×
392
    }
393
    return performDrop(
×
394
        cleanedSrc, cleanedDest, action,
395
        QMessageBox::question(
×
396
            qobject_cast<QWidget *>(QObject::parent()), tr("Force overwrite?"),
×
397
            tr("overwrite %1 with %2?").arg(cleanedDest, cleanedSrc),
×
398
            QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes);
399
  default:
×
400
    qWarning() << "executeDropAction: unexpected ItemKind, ignoring drop";
×
401
    return false;
×
402
  }
403
}
3 ✔
404

405
auto StoreModel::performDrop(const QString &cleanedSrc,
×
406
                             const QString &cleanedDest, Qt::DropAction action,
407
                             bool force) -> bool {
408
  if (!m_pass) {
×
409
    return false;
410
  }
411
  if (action == Qt::MoveAction) {
×
412
    m_pass->Move(cleanedSrc, cleanedDest, force);
×
413
  } else if (action == Qt::CopyAction) {
×
414
    m_pass->Copy(cleanedSrc, cleanedDest, force);
×
415
  }
416
  return true;
417
}
418

419
/**
420
 * @brief StoreModel::lessThan
421
 * @param source_left
422
 * @param source_right
423
 * @return
424
 */
425
auto StoreModel::lessThan(const QModelIndex &source_left,
2 ✔
426
                          const QModelIndex &source_right) const -> bool {
427
/* matches logic in QFileSystemModelSorter::compareNodes() */
428
#ifndef Q_OS_MAC
429
  if (fs && (source_left.column() == 0 || source_left.column() == 1)) {
2 ✔
430
    bool leftD = fs->isDir(source_left);
2 ✔
431
    bool rightD = fs->isDir(source_right);
2 ✔
432

433
    if (leftD ^ rightD) {
2 ✔
434
      return leftD;
435
    }
436
  }
437
#endif
438

439
  return QSortFilterProxyModel::lessThan(source_left, source_right);
1 ✔
440
}
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