From 922ccb27fba27328741aafdf6bd7a4258d193e88 Mon Sep 17 00:00:00 2001 From: Méven Car Date: Thu, 18 Jun 2026 09:08:39 +0000 Subject: 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. --- src/views/viewproperties.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/views') diff --git a/src/views/viewproperties.cpp b/src/views/viewproperties.cpp index 94262e651..f461ebb89 100644 --- a/src/views/viewproperties.cpp +++ b/src/views/viewproperties.cpp @@ -14,6 +14,10 @@ #include #include +#ifdef Q_OS_WIN +#include +#endif + #include #include @@ -186,7 +190,14 @@ ViewProperties::ViewProperties(const QUrl &url) if (!useDestinationDir) { const QFileInfo dirInfo(m_filePath); const QFileInfo fileInfo(m_filePath + QDir::separator() + ViewPropertiesFileName); - useDestinationDir = !dirInfo.isWritable() || (dirInfo.size() > 0 && fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable())); + bool dirWritable = dirInfo.isWritable(); +#ifdef Q_OS_WIN + if (dirWritable) { + const DWORD attrs = GetFileAttributesW(reinterpret_cast(m_filePath.utf16())); + dirWritable = (attrs == INVALID_FILE_ATTRIBUTES) || !(attrs & FILE_ATTRIBUTE_READONLY); + } +#endif + useDestinationDir = !dirWritable || (dirInfo.size() > 0 && fileInfo.exists() && !(fileInfo.isReadable() && fileInfo.isWritable())); } if (useDestinationDir) { -- cgit v1.3.1