Skip to content

Commit

Permalink
always propagate locked status to read-only or read/write for real file
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mgallien committed Jun 29, 2023
1 parent 7d011fa commit fa18fa7
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,14 @@ void PropagateDownloadFile::downloadFinished()
}
}

if (_item->_locked == SyncFileItem::LockStatus::LockedItem && (_item->_lockOwnerType != SyncFileItem::LockOwnerType::UserLock || _item->_lockOwnerId != propagator()->account()->davUser())) {
qCDebug(lcPropagateDownload()) << "file is locked: making it read only";
FileSystem::setFileReadOnly(filename, true);
} else {
qCDebug(lcPropagateDownload()) << "file is not locked: making it 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));

Expand Down Expand Up @@ -1262,12 +1270,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...
Expand Down Expand Up @@ -1346,6 +1348,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()) << "file is locked: making it read only";
FileSystem::setFileReadOnly(fn, true);
} else {
qCDebug(lcPropagateDownload()) << "file is not locked: making it 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;
Expand Down

0 comments on commit fa18fa7

Please sign in to comment.