┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMéven Car <[email protected]>2026-06-18 09:08:39 +0000
committerMéven Car <[email protected]>2026-06-18 10:30:38 +0000
commit922ccb27fba27328741aafdf6bd7a4258d193e88 (patch)
tree492f48166c7a92f9d15634fcf116f8ed04eb5a76 /src/tests
parent8cbae43d2269a056b530e10ae8c11168bc66ebb5 (diff)
viewproperties: detect read-only directories on Windows
On Windows QFileInfo::isWritable() returns true for a directory that carries the read-only attribute, because the attribute does not prevent creating child files. It does prevent writing the directory's own extended attribute, the Alternate Data Stream where the view properties are stored, so the save fails with access denied and the settings are lost. Detect the read-only attribute with GetFileAttributesW and store the view properties in the destination directory instead, the same way a directory without write permission is handled on other platforms. The read-only directory test checks that the properties land in the destination directory.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/viewpropertiestest.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp
index 1d9e886e1..73a26f289 100644
--- a/src/tests/viewpropertiestest.cpp
+++ b/src/tests/viewpropertiestest.cpp
@@ -109,45 +109,34 @@ void ViewPropertiesTest::testReadOnlyDirectory()
QVERIFY(QFile(localFolder).setPermissions(QFileDevice::ReadOwner));
QScopedPointer<ViewProperties> props(new ViewProperties(testDirUrl));
+#ifdef Q_OS_WIN
+ const QString destinationDir = props->destinationDir(QStringLiteral("local")) + QDir::separator() + QString(localFolder).remove(QLatin1Char(':'));
+#else
+ const QString destinationDir = props->destinationDir(QStringLiteral("local")) + localFolder;
+#endif
+
QVERIFY(props->isAutoSaveEnabled());
props->setSortRole("someNewSortRole");
props.reset();
-#ifdef Q_OS_WIN
- // On Windows the read-only attribute is not honored on directories: files and
- // Alternate Data Streams can still be created inside them. The properties are
- // therefore stored locally rather than redirected to the destination directory.
- KFileMetaData::UserMetaData metadata(localFolder);
- if (metadata.isSupported()) {
- QVERIFY(metadata.hasAttribute("kde.fm.viewproperties#1"));
- } else {
- QVERIFY(QFile::exists(dotDirectoryFile));
- }
-#else
- // On a directory without write permission the properties are redirected to the
- // destination directory, leaving the local directory untouched.
- const QString destinationDir = props->destinationDir(QStringLiteral("local")) + localFolder;
QVERIFY(QDir(destinationDir).exists());
QVERIFY(!QFile::exists(dotDirectoryFile));
KFileMetaData::UserMetaData metadata(localFolder);
- QVERIFY(metadata.attribute(QStringLiteral("kde.fm.viewproperties#1")).isEmpty());
-#endif
+ const QString viewProperties = metadata.attribute(QStringLiteral("kde.fm.viewproperties#1"));
+ QVERIFY(viewProperties.isEmpty());
- // The stored value round-trips regardless of where it was written.
props.reset(new ViewProperties(testDirUrl));
QVERIFY(props->isAutoSaveEnabled());
QCOMPARE(props->sortRole(), "someNewSortRole");
props.reset();
-#ifndef Q_OS_WIN
- KFileMetaData::UserMetaData destMetadata(destinationDir);
- if (destMetadata.isSupported()) {
- QVERIFY(destMetadata.hasAttribute("kde.fm.viewproperties#1"));
+ metadata = KFileMetaData::UserMetaData(destinationDir);
+ if (metadata.isSupported()) {
+ QVERIFY(metadata.hasAttribute("kde.fm.viewproperties#1"));
} else {
QVERIFY(QFile::exists(destinationDir + "/.directory"));
}
-#endif
// un-restrict write permissions
QFile(localFolder).setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner);