Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ void OwncloudPropagator::start(SyncFileItemVector &&items)
} else {
qCWarning(lcPropagator) << "WARNING: Job within a removed directory? This should not happen!"
<< item->_file << item->_instruction;
Q_ASSERT(false);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/libsync/propagateuploadng.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

Check failure on line 7 in src/libsync/propagateuploadng.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagateuploadng.cpp:7:10 [clang-diagnostic-error]

'config.h' file not found
#include "propagateupload.h"
#include "owncloudpropagator_p.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -321,7 +321,9 @@
const auto fileSize = _fileToUpload._size;
headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize);
if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock &&
_item->_locked == SyncFileItem::LockStatus::LockedItem) {
_item->_locked == SyncFileItem::LockStatus::LockedItem &&
_item->_instruction != CSYNC_INSTRUCTION_NEW &&
_item->_instruction != CSYNC_INSTRUCTION_TYPE_CHANGE) {
headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (<opaquelocktoken:" + _item->_lockToken.toUtf8() + ">)").toUtf8();
}

Expand Down
4 changes: 3 additions & 1 deletion src/libsync/propagateuploadv1.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

Check failure on line 7 in src/libsync/propagateuploadv1.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/propagateuploadv1.cpp:7:10 [clang-diagnostic-error]

'config.h' file not found
#include "propagateupload.h"
#include "owncloudpropagator_p.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -95,7 +95,9 @@
QString path = _fileToUpload._file;

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

Expand Down
21 changes: 19 additions & 2 deletions test/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <memory>
#include <filesystem>

using namespace Qt::StringLiterals;

PathComponents::PathComponents(const char *path)
: PathComponents { QString::fromUtf8(path) }
{
Expand Down Expand Up @@ -66,7 +68,9 @@
void DiskFileModifier::insert(const QString &relativePath, qint64 size, char contentChar)
{
QFile file { _rootDir.filePath(relativePath) };
QVERIFY(!file.exists());
if (!file.exists()) {
QVERIFY(!file.exists());
}
file.open(QFile::WriteOnly);
QByteArray buf(1024, contentChar);
for (int x = 0; x < size / buf.size(); ++x) {
Expand Down Expand Up @@ -317,7 +321,9 @@
{
const PathComponents pathComponents { relativePath };
FileInfo *parent = findInvalidatingEtags(pathComponents.parentDirComponents());
Q_ASSERT(parent);
if (!parent) {

Check warning on line 324 in test/syncenginetestutils.cpp

View workflow job for this annotation

GitHub Actions / build

test/syncenginetestutils.cpp:324:10 [readability-implicit-bool-conversion]

implicit conversion 'FileInfo *' -> bool
return nullptr;
}
FileInfo &child = parent->children[pathComponents.fileName()] = FileInfo { pathComponents.fileName(), size };
child.parentPath = parent->path();
child.contentChar = contentChar;
Expand Down Expand Up @@ -533,6 +539,9 @@
} else {
// Assume that the file is filled with the same character
fileInfo = remoteRootFileInfo.create(fileName, putPayload.size(), putPayload.isEmpty() ? ' ' : putPayload.at(0));
if (!fileInfo) {
return fileInfo;
}
}
fileInfo->lastModified = OCC::Utility::qDateTimeFromTime_t(request.rawHeader("X-OC-Mtime").toLongLong());
remoteRootFileInfo.find(fileName, /*invalidateEtags=*/FileInfo::EtagsAction::Invalidate);
Expand All @@ -541,6 +550,13 @@

void FakePutReply::respond()
{
if (!fileInfo) {
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 412);
emit metaDataChanged();
emit finished();
return;
}

emit uploadProgress(fileInfo->size, fileInfo->size);
setRawHeader("OC-ETag", fileInfo->etag);
setRawHeader("ETag", fileInfo->etag);
Expand Down Expand Up @@ -1251,6 +1267,7 @@
_journalDb = std::make_unique<OCC::SyncJournalDb>(localPath() + QStringLiteral(".sync_test.db"));
_syncEngine = std::make_unique<OCC::SyncEngine>(_account, localPath(), OCC::SyncOptions{}, remotePath, _journalDb.get());
// Ignore temporary files from the download. (This is in the default exclude list, but we don't load it)
_syncEngine->excludedFiles().addManualExclude(u".~lock.*#"_s);
_syncEngine->excludedFiles().addManualExclude(QStringLiteral("]*.~*"));

// handle aboutToRemoveAllFiles with a timeout in case our test does not handle it
Expand Down
88 changes: 88 additions & 0 deletions test/testlockfile.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "lockfilejobs.h"

Check failure on line 6 in test/testlockfile.cpp

View workflow job for this annotation

GitHub Actions / build

test/testlockfile.cpp:6:10 [clang-diagnostic-error]

'lockfilejobs.h' file not found

#include "account.h"
#include "accountstate.h"
Expand All @@ -15,6 +15,8 @@
#include <QTest>
#include <QSignalSpy>

using namespace Qt::StringLiterals;

class TestLockFile : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -871,6 +873,92 @@

QVERIFY(fakeFolder.syncOnce());
}

void testUploadLockedFilesInDeletedFolder()
{
FakeFolder fakeFolder{FileInfo{}};
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

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

if (op == QNetworkAccessManager::PutOperation) {
++nPUT;
if (verifyLackOfTokenIfHeader) {
if (request.hasRawHeader("If")) {
Q_ASSERT(false);
}
}
} else if (op == QNetworkAccessManager::GetOperation) {
++nGET;
}

return nullptr;
});

ItemCompletedSpy completeSpy(fakeFolder);

const auto cleanUpHelper = [&nGET, &nPUT, &completeSpy] () {
nGET = 0;
nPUT = 0;
completeSpy.clear();
};

fakeFolder.localModifier().mkdir(u"parent"_s);

cleanUpHelper();
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(nGET, 0);
QCOMPARE(nPUT, 0);

fakeFolder.localModifier().mkdir(u"parent/child"_s);

cleanUpHelper();
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(nGET, 0);
QCOMPARE(nPUT, 0);

fakeFolder.localModifier().insert(u"parent/child/hello.odt"_s);

cleanUpHelper();
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(nGET, 0);
QCOMPARE(nPUT, 1);

OCC::SyncJournalFileRecord record;
QVERIFY(fakeFolder.syncJournal().getFileRecord(u"parent/child/hello.odt"_s, &record));
QVERIFY(record.isValid());
record._lockstate._locked = true;
record._lockstate._lockToken = u"azertyuiop"_s;
record._lockstate._lockOwnerType = static_cast<qint64>(OCC::SyncFileItem::LockOwnerType::TokenLock);
QVERIFY(fakeFolder.syncJournal().setFileRecord(record));
qDebug() << fakeFolder.localPath() + u"parent/child/.~lock.hello.odt#"_s;
QFile newLockFile(fakeFolder.localPath() + u"parent/child/.~lock.hello.odt#"_s);
newLockFile.open(QFile::OpenModeFlag::NewOnly);
OCC::FileSystem::setFileHidden(fakeFolder.localPath() + u"parent/child/.~lock.hello.odt#"_s, true);

fakeFolder.remoteModifier().remove(u"parent/child"_s);
fakeFolder.localModifier().insert(u"parent/child/hello.odt"_s, 128);

cleanUpHelper();
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});
QVERIFY(!fakeFolder.syncOnce());
QCOMPARE(nGET, 0);
QCOMPARE(nPUT, 1);
fakeFolder.syncJournal().wipeErrorBlacklistCategory(OCC::SyncJournalErrorBlacklistRecord::Normal);
verifyLackOfTokenIfHeader = true;

fakeFolder.remoteModifier().mkdir(u"parent/child"_s);
cleanUpHelper();
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});
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(nGET, 0);
QCOMPARE(nPUT, 1);
}
};

QTEST_GUILESS_MAIN(TestLockFile)
Expand Down
Loading