Merge pull request #5841 from nextcloud/bugfix/lockedFileShouldBeReadOnly

always propagate locked status to read-only or read/write for real file
This commit is contained in:
Matthieu Gallien 2023-07-12 14:26:38 +02:00 committed by GitHub
commit d648fa14e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 8 deletions

View File

@ -1198,8 +1198,15 @@ void PropagateDownloadFile::downloadFinished()
}
}
// Apply the remote permissions
FileSystem::setFileReadOnlyWeak(_tmpFile.fileName(), !_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite));
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(_tmpFile.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::setFileReadOnlyWeak(_tmpFile.fileName(), (!_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)));
}
const auto isConflict = (_item->_instruction == CSYNC_INSTRUCTION_CONFLICT
&& (QFileInfo(filename).isDir() || !FileSystem::fileEquals(filename, _tmpFile.fileName()))) ||
@ -1262,12 +1269,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 +1347,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::setFileReadOnlyWeak(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;

View File

@ -67,6 +67,10 @@ class TestPermissions : public QObject
Q_OBJECT
private slots:
void initTestCase()
{
OCC::Logger::instance()->setLogDebug(true);
}
void t7pl()
{

View File

@ -85,6 +85,11 @@ class TestSyncEngine : public QObject
Q_OBJECT
private slots:
void initTestCase()
{
OCC::Logger::instance()->setLogDebug(true);
}
void testFileDownload() {
FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
ItemCompletedSpy completeSpy(fakeFolder);