Skip to content

Commit bde3d74

Browse files
committed
fix: ensure proper upload of locked files
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent 867b0f1 commit bde3d74

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/libsync/propagateuploadng.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ void PropagateUploadFileNG::finishUpload()
321321
const auto fileSize = _fileToUpload._size;
322322
headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize);
323323
if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock &&
324-
_item->_locked == SyncFileItem::LockStatus::LockedItem) {
324+
_item->_locked == SyncFileItem::LockStatus::LockedItem &&
325+
_item->_instruction != CSYNC_INSTRUCTION_NEW &&
326+
_item->_instruction != CSYNC_INSTRUCTION_TYPE_CHANGE) {
325327
headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (<opaquelocktoken:" + _item->_lockToken.toUtf8() + ">)").toUtf8();
326328
}
327329

src/libsync/propagateuploadv1.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ void PropagateUploadFileV1::startNextChunk()
9595
QString path = _fileToUpload._file;
9696

9797
if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock &&
98-
_item->_locked == SyncFileItem::LockStatus::LockedItem) {
98+
_item->_locked == SyncFileItem::LockStatus::LockedItem &&
99+
_item->_instruction != CSYNC_INSTRUCTION_NEW &&
100+
_item->_instruction != CSYNC_INSTRUCTION_TYPE_CHANGE) {
99101
headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (<opaquelocktoken:" + _item->_lockToken.toUtf8() + ">)").toUtf8();
100102
}
101103

test/testlockfile.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,19 @@ private slots:
880880
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
881881

882882
int nGET = 0, nPUT = 0;
883+
auto verifyLackOfTokenIfHeader = false;
883884
QObject parent;
884885
fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData) -> QNetworkReply * {
885886
Q_UNUSED(outgoingData)
886887
Q_UNUSED(request)
887888

888889
if (op == QNetworkAccessManager::PutOperation) {
889890
++nPUT;
891+
if (verifyLackOfTokenIfHeader) {
892+
if (request.hasRawHeader("If")) {
893+
Q_ASSERT(false);
894+
}
895+
}
890896
} else if (op == QNetworkAccessManager::GetOperation) {
891897
++nGET;
892898
}
@@ -943,11 +949,13 @@ private slots:
943949
QVERIFY(!fakeFolder.syncOnce());
944950
QCOMPARE(nGET, 0);
945951
QCOMPARE(nPUT, 1);
952+
fakeFolder.syncJournal().wipeErrorBlacklistCategory(OCC::SyncJournalErrorBlacklistRecord::Normal);
953+
verifyLackOfTokenIfHeader = true;
946954

947955
fakeFolder.remoteModifier().mkdir(u"parent/child"_s);
948956
cleanUpHelper();
949957
fakeFolder.syncEngine().setLocalDiscoveryOptions(OCC::LocalDiscoveryStyle::DatabaseAndFilesystem, {u"parent"_s, u"parent/child"_s, u"parent/child/.~lock.hello.odt#"_s, u"parent/child/hello.odt"_s});
950-
QVERIFY(!fakeFolder.syncOnce());
958+
QVERIFY(fakeFolder.syncOnce());
951959
QCOMPARE(nGET, 0);
952960
QCOMPARE(nPUT, 1);
953961
}

0 commit comments

Comments
 (0)