]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
always propagate locked status to read-only or read/write for real file
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 23 Jun 2023 11:49:22 +0000 (13:49 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Wed, 12 Jul 2023 11:41:46 +0000 (13:41 +0200)
make sure that a file locked that would not be modifiable by the
current client is read-only on storage

also make sure we make a file read/write when modification can happen
again

Close #5537

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/propagatedownload.cpp

index 2edd3c4c5ba8250440999565e3a2cd78b3d34af3..93b66526ca9f2948e79508d5f75f16d90788c779 100644 (file)
@@ -1198,6 +1198,16 @@ void PropagateDownloadFile::downloadFinished()
         }
     }
 
+    if (_item->_locked == SyncFileItem::LockStatus::LockedItem && (_item->_lockOwnerType != SyncFileItem::LockOwnerType::UserLock || _item->_lockOwnerId != propagator()->account()->davUser())) {
+        qCDebug(lcPropagateDownload()) << _tmpFile << "file is locked: making it read only";
+        FileSystem::setFileReadOnly(filename, true);
+    } else {
+        qCDebug(lcPropagateDownload()) << _tmpFile << "file is not locked: making it"
+                                       << ((!_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)) ? "read only"
+                                                                                                                                            : "read write");
+        FileSystem::setFileReadOnly(filename, (!_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)));
+    }
+
     // Apply the remote permissions
     FileSystem::setFileReadOnlyWeak(_tmpFile.fileName(), !_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite));
 
@@ -1262,12 +1272,6 @@ void PropagateDownloadFile::downloadFinished()
         return;
     }
 
-    qCInfo(lcPropagateDownload()) << propagator()->account()->davUser() << propagator()->account()->davDisplayName() << propagator()->account()->displayName();
-    if (_item->_locked == SyncFileItem::LockStatus::LockedItem && (_item->_lockOwnerType != SyncFileItem::LockOwnerType::UserLock || _item->_lockOwnerId != propagator()->account()->davUser())) {
-        qCInfo(lcPropagateDownload()) << "file is locked: making it read only";
-        FileSystem::setFileReadOnly(filename, true);
-    }
-
     FileSystem::setFileHidden(filename, false);
 
     // Maybe we downloaded a newer version of the file than we thought we would...
@@ -1346,6 +1350,14 @@ void PropagateDownloadFile::updateMetadata(bool isConflict)
         handleRecallFile(fn, propagator()->localPath(), *propagator()->_journal);
     }
 
+    if (_item->_locked == SyncFileItem::LockStatus::LockedItem && (_item->_lockOwnerType != SyncFileItem::LockOwnerType::UserLock || _item->_lockOwnerId != propagator()->account()->davUser())) {
+        qCDebug(lcPropagateDownload()) << fn << "file is locked: making it read only";
+        FileSystem::setFileReadOnly(fn, true);
+    } else {
+        qCDebug(lcPropagateDownload()) << fn << "file is not locked: making it" << ((!_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)) ? "read only" : "read write");
+        FileSystem::setFileReadOnly(fn, (!_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)));
+    }
+
     qint64 duration = _stopwatch.elapsed();
     if (isLikelyFinishedQuickly() && duration > 5 * 1000) {
         qCWarning(lcPropagateDownload) << "WARNING: Unexpectedly slow connection, took" << duration << "msec for" << _item->_size - _resumeStart << "bytes for" << _item->_file;