diff options
| author | Sergey Katunin <[email protected]> | 2026-01-12 12:57:40 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2026-01-12 12:57:40 +0000 |
| commit | b9b06174afca99d7fe544940b950a7323631271a (patch) | |
| tree | 23c196c7eabba40d0c500001ec339649b4bd2feb /src/tests/viewpropertiestest.cpp | |
| parent | 6cd94cbecbbee52ae380e51671a4160272195fee (diff) | |
viewproperties: remove temp file after loading defaultConfig
It turns out that since f6c97d52220be9bd996b71309051e56ff7aa1834 a temp file is created here with each `save()` call for this default config, which is not deleted later. In another place where `defaultProperties()` is called for `m_node`, the file is deleted in the destructor of this class. But it is not deleted here.
So, remove temp file after loading defaultConfig or it will create temp file on each save() operation in /tmp folder.
Also keep the global/.directory file when xattr isn't supported.
BUG: 510500
Diffstat (limited to 'src/tests/viewpropertiestest.cpp')
| -rw-r--r-- | src/tests/viewpropertiestest.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp index 1836f0445..ff3d93cdb 100644 --- a/src/tests/viewpropertiestest.cpp +++ b/src/tests/viewpropertiestest.cpp @@ -27,6 +27,7 @@ private Q_SLOTS: void testAutoSave(); void testParamMigrationToFileAttr(); void testParamMigrationToFileAttrKeepDirectory(); + void testGlobalDefaultConfigFromDirectory(); void testExtendedAttributeFull(); void testUseAsDefaultViewSettings(); void testUseAsCustomDefaultViewSettings(); @@ -64,6 +65,10 @@ void ViewPropertiesTest::cleanup() GeneralSettings::self()->setGlobalViewProps(m_globalViewProps); GeneralSettings::self()->save(); + + // Check that we do not have temp files left after test case. + QDir tempDir(QDir::tempPath()); + QVERIFY(tempDir.entryList(QStringList() << QCoreApplication::applicationName() + "*", QDir::Files).length() == 0); } /** @@ -235,6 +240,55 @@ ThoseShouldBeKept=true QVERIFY(QFile::exists(dotDirectoryFilePath)); } +void ViewPropertiesTest::testGlobalDefaultConfigFromDirectory() +{ + QUrl globalPropertiesPath = + QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/view_properties/").append(QStringLiteral("global"))); + QVERIFY(QDir().mkpath(globalPropertiesPath.toLocalFile())); + + QString dotDirectoryFilePath = globalPropertiesPath.toLocalFile() + "/.directory"; + QVERIFY(!QFile::exists(dotDirectoryFilePath)); + + auto cleanupGlobalDir = qScopeGuard([globalPropertiesPath, dotDirectoryFilePath] { + QFile::remove(dotDirectoryFilePath); + QDir().rmdir(globalPropertiesPath.toLocalFile()); + }); + + const char *settingsContent = R"SETTINGS(" +[Dolphin] +Version=4 +ViewMode=1 +Timestamp=2023,12,29,10,44,15.793 +VisibleRoles=text,CustomizedDetails,Details_text,Details_modificationtime,Details_type + +[Settings] +HiddenFilesShown=true + +[Other] +ThoseShouldBeKept=true +)SETTINGS"; + auto dotDirectoryFile = QFile(dotDirectoryFilePath); + QVERIFY(dotDirectoryFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)); + QTextStream out(&dotDirectoryFile); + out << settingsContent; + dotDirectoryFile.close(); + + ViewProperties props(m_testDir->url()); + props.save(); + + // We delete a temporary file in 'ViewProperties::save()' after reading the default config, + // and that temp file is created as copy from '.directory' if we have metadata enabled. + // + // But it can be original '.directory' instead of temp file, + // if we read default config from 'global' directory, which does not support attributes. + // So we make sure that it is not deleted here, + // because we do not want to delete '.directory' file. + QVERIFY(QFile::exists(dotDirectoryFilePath)); + + QVERIFY(props.hiddenFilesShown()); + QCOMPARE(props.viewMode(), DolphinView::Mode::DetailsView); +} + void ViewPropertiesTest::testExtendedAttributeFull() { #ifndef Q_OS_UNIX |
