┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Katunin <[email protected]>2026-01-12 12:57:40 +0000
committerMéven Car <[email protected]>2026-01-12 12:57:40 +0000
commitb9b06174afca99d7fe544940b950a7323631271a (patch)
tree23c196c7eabba40d0c500001ec339649b4bd2feb
parent6cd94cbecbbee52ae380e51671a4160272195fee (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
-rw-r--r--src/tests/viewpropertiestest.cpp54
-rw-r--r--src/views/viewproperties.cpp11
2 files changed, 65 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
diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp
index 8bf3b2531..8be3d408e 100644
--- a/src/views/viewproperties.cpp
+++ b/src/views/viewproperties.cpp
@@ -73,6 +73,7 @@ ViewPropertySettings *ViewProperties::loadProperties(const QString &folderPath)
// load from metadata
const QString viewPropertiesString = metadata.attribute(QStringLiteral("kde.fm.viewproperties#1"));
if (viewPropertiesString.isEmpty()) {
+ QFile::remove(tempFile->fileName());
return nullptr;
}
// load view properties from xattr to temp file then loads into ViewPropertySettings
@@ -532,6 +533,16 @@ void ViewProperties::save()
const auto items = m_node->items();
const auto defaultConfig = defaultProperties();
+
+ auto cleanupDefaultConfig = qScopeGuard([defaultConfig] {
+ // Usually it should be a temporary file, but it can be '.directory',
+ // if we read this file from the 'global' directory .directory file it means it did not support attributes,
+ // then keep the '.directory' file from 'global' here, otherwise we can remove it.
+ if (!defaultConfig->config()->name().endsWith(ViewPropertiesFileName)) {
+ QFile::remove(defaultConfig->config()->name());
+ }
+ });
+
bool allDefault = true;
for (const auto item : items) {
if (item->name() == "Timestamp") {