MailJD nbsp;·nbsp; Test Dashboard nbsp;·nbsp; Coverage
LCOV - code coverage report
Current view: top level - data - DatabaseSecurity.h (source / functions) Coverage Total Hit
Test: MailJD Coverage (Unit + E2E) Lines: 85.2 % 27 23
Test Date: 2026-06-21 21:10:19 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 54.8 % 42 23

             Branch data     Line data    Source code
       1                 :             : #pragma once
       2                 :             : 
       3                 :             : #include <QDir>
       4                 :             : #include <QFile>
       5                 :             : #include <QFileInfo>
       6                 :             : #include <QString>
       7                 :             : 
       8                 :             : namespace DatabaseSecurity {
       9                 :             : 
      10                 :         745 : inline bool preparePath(const QString &dbPath) {
      11         [ +  + ]:         745 :   if (dbPath == QLatin1String(":memory:"))
      12                 :          21 :     return true;
      13                 :             : 
      14         [ +  - ]:         724 :   const QFileInfo info(dbPath);
      15         [ +  - ]:         724 :   const QString parentPath = info.absolutePath();
      16   [ +  -  +  -  :         724 :   if (!QDir(parentPath).exists()) {
                   +  + ]
      17   [ +  -  +  -  :           4 :     if (!QDir().mkpath(parentPath))
                   +  - ]
      18                 :           4 :       return false;
      19         [ #  # ]:           0 :     if (!QFile::setPermissions(
      20         [ #  # ]:           0 :             parentPath, QFileDevice::ReadOwner | QFileDevice::WriteOwner |
      21                 :             :                             QFileDevice::ExeOwner))
      22                 :           0 :       return false;
      23                 :             :   }
      24                 :             : 
      25   [ +  -  +  + ]:         720 :   if (info.exists())
      26                 :         293 :     return true;
      27                 :             : 
      28         [ +  - ]:         427 :   QFile file(dbPath);
      29         [ +  - ]:         427 :   return file.open(QIODevice::WriteOnly | QIODevice::NewOnly,
      30                 :         427 :                    QFileDevice::ReadOwner | QFileDevice::WriteOwner);
      31                 :         724 : }
      32                 :             : 
      33                 :         737 : inline bool restrictExistingFile(const QString &dbPath) {
      34         [ +  + ]:         737 :   if (dbPath == QLatin1String(":memory:"))
      35                 :          21 :     return true;
      36                 :             : 
      37         [ +  - ]:         716 :   const QFileInfo info(dbPath);
      38   [ +  -  -  + ]:         716 :   if (!info.exists())
      39                 :           0 :     return false;
      40                 :             : 
      41                 :             :   const auto ownerPermissions =
      42         [ +  - ]:         716 :       info.permissions() &
      43                 :        1432 :       (QFileDevice::ReadOwner | QFileDevice::WriteOwner);
      44         [ +  - ]:         716 :   return QFile::setPermissions(dbPath, ownerPermissions);
      45                 :         716 : }
      46                 :             : 
      47                 :             : } // namespace DatabaseSecurity
        

Generated by: LCOV version 2.0-1