Files
keepassxc/tests/TestDatabase.h
T
Janek Bevendorff cdb9e36adb Change TempFile saving method to use atomic renames
Fixes #13970

The previous TempFile saving method failed under Qt6 on certain remote file systems that don't support hard-linking or O_TMPFILE renames, such as remote SMB shares. Here, QFile::rename() created an unamed Q_TMPFILE, and tried to rename it with linkat(), which failed. Since QFile::rename() does not do file replacements, KeePassXC had to remove the target before moving the new file in place, which could cause to data loss when the rename failed.

This patch changes TempFile to a hybrid approach: The database is first written to a temporary file. The temporary file is committed to disk, and then streamed to a named sibling of the target file. Streaming avoids using QFile::copy() or QFile::rename(), which can trigger the failure. After straming the file back, the target file is replaced atomically (if possible) with the sibling.
2026-11-12 20:47:39 +01:00

48 lines
1.5 KiB
C++

/*
* Copyright (C) 2017 Vladimir Svyatski <[email protected]>
* Copyright (C) 2017 KeePassXC Team <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_TESTDATABASE_H
#define KEEPASSX_TESTDATABASE_H
#include <QObject>
class TestDatabase : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void testOpen();
void testSave();
void testSaveStaged_data();
void testSaveStaged();
void testSaveStagedFailure_data();
void testSaveStagedFailure();
void testSaveAs();
void testSignals();
void testEmptyRecycleBinOnDisabled();
void testEmptyRecycleBinOnNotCreated();
void testEmptyRecycleBinOnEmpty();
void testEmptyRecycleBinWithHierarchicalData();
void testCustomIcons();
void testExternallyModified();
void testCustomAttributeKeys();
};
#endif // KEEPASSX_TESTDATABASE_H