diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-09-21 13:34:02 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-09-22 13:50:48 +0300 |
commit | 0919a2611edc20ce9dd7cb1eda3edc83522ffd3d (patch) | |
tree | e58717a25884ff682d3004269cc521c3312e9962 | |
parent | 2a95f3b442e6f75eda39347c3c08ea84fb436335 (diff) |
Use NtfsPermissionLookupRAII when checking for readable/writeabel
-rw-r--r-- | src/common/filesystembase.cpp | 9 | ||||
-rw-r--r-- | src/gui/accountmanager.cpp | 3 | ||||
-rw-r--r-- | src/gui/accountsettings.cpp | 2 | ||||
-rw-r--r-- | src/gui/folder.cpp | 3 | ||||
-rw-r--r-- | src/gui/folderman.cpp | 4 | ||||
-rw-r--r-- | src/libsync/configfile.cpp | 3 |
6 files changed, 23 insertions, 1 deletions
diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index 066e20373..640589ca3 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -100,6 +100,7 @@ void FileSystem::setFileReadOnly(const QString &filename, bool readonly) if (!readonly) { permissions |= defaultWritePermissions; } + // Warning: This function does not manipulate ACLs, which may limit its effectiveness. file.setPermissions(permissions); } @@ -197,6 +198,10 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName, #else //Q_OS_WIN // You can not overwrite a read-only file on windows. + + Utility::NtfsPermissionLookupRAII ntfs_perm; + // Warning: This function does not manipulate ACLs, which may limit its effectiveness. + // this renders this check kind of pointless if (!QFileInfo(destinationFileName).isWritable()) { setFileReadOnly(destinationFileName, false); } @@ -362,6 +367,10 @@ bool FileSystem::remove(const QString &fileName, QString *errorString) #ifdef Q_OS_WIN // You cannot delete a read-only file on windows, but we want to // allow that. + + Utility::NtfsPermissionLookupRAII ntfs_perm; + // Warning: This function does not manipulate ACLs, which may limit its effectiveness. + // this renders this check kind of pointless if (!QFileInfo(fileName).isWritable()) { setFileReadOnly(fileName, false); } diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 595ee8858..b7ea4f36e 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -153,6 +153,9 @@ bool AccountManager::restoreFromLegacySettings() qCInfo(lcAccountManager) << "Migrate: checking old config " << oCCfgFile; +#ifdef Q_OS_WIN + Utility::NtfsPermissionLookupRAII ntfs_perm; +#endif QFileInfo fi(oCCfgFile); if (fi.isReadable()) { std::unique_ptr<QSettings> oCSettings(new QSettings(oCCfgFile, QSettings::IniFormat)); diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index ecf973c10..2cffeba70 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -962,7 +962,7 @@ void AccountSettings::refreshSelectiveSyncStatus() QString msg; int cnt = 0; for (Folder *folder : FolderMan::instance()->map()) { - if (folder->accountState() != _accountState) { + if (folder->accountState() != _accountState || !folder->ok()) { continue; } diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index a8fd26c85..0dc9026e1 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -159,6 +159,9 @@ Folder::~Folder() bool Folder::checkLocalPath() { +#ifdef Q_OS_WIN + Utility::NtfsPermissionLookupRAII ntfs_perm; +#endif const QFileInfo fi(_definition.localPath); _canonicalLocalPath = fi.canonicalFilePath(); #ifdef Q_OS_MAC diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index da54e3eaf..f3a2ac8ff 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -517,6 +517,10 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat // check the unescaped variant (for the case when the filename comes out // of the directory listing). If the file does not exist, escape the // file and try again. + +#ifdef Q_OS_WIN + Utility::NtfsPermissionLookupRAII ntfs_perm; +#endif QFileInfo cfgFile(_folderConfigPath, file); if (!cfgFile.exists()) { diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index fdb61b7b3..8cd164348 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -278,6 +278,9 @@ static const QLatin1String exclFile("sync-exclude.lst"); QString ConfigFile::excludeFile(Scope scope) const { +#ifdef Q_OS_WIN + Utility::NtfsPermissionLookupRAII ntfs_perm; +#endif // prefer sync-exclude.lst, but if it does not exist, check for // exclude.lst for compatibility reasons in the user writeable // directories. |