Skip to content
Merged
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
50 changes: 36 additions & 14 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
Expand Down Expand Up @@ -756,13 +756,8 @@
item->_isLivePhoto = serverEntry.isLivePhoto;
item->_livePhotoFile = serverEntry.livePhotoFile;

if (serverEntry.isValid()) {
item->_folderQuota.bytesUsed = serverEntry.folderQuota.bytesUsed;
item->_folderQuota.bytesAvailable = serverEntry.folderQuota.bytesAvailable;
} else {
item->_folderQuota.bytesUsed = -1;
item->_folderQuota.bytesAvailable = -1;
}
item->_folderQuota.bytesUsed = serverEntry.folderQuota.bytesUsed;
item->_folderQuota.bytesAvailable = serverEntry.folderQuota.bytesAvailable;

// Check for missing server data
{
Expand Down Expand Up @@ -1085,23 +1080,45 @@
int64_t ProcessDirectoryJob::folderBytesAvailable(const SyncFileItemPtr &item, const FolderQuota::ServerEntry serverEntry) const
{
const auto unlimitedFreeSpace = -3;
if (item->_size == 0 || item->_direction != SyncFileItem::Up || item->isDirectory() || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE) {
const auto isTypeChange = item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE;
const auto isUpdateMetadataOrRename = item->_instruction != CSYNC_INSTRUCTION_SYNC && item->_instruction != CSYNC_INSTRUCTION_NEW;
const auto isFileDownloadOrDirectory = item->_direction != SyncFileItem::Up || item->isDirectory();

qCDebug(lcDisco) << "Checking quota for item:" << item->_file
<< "isTypeChange?" << isTypeChange
<< "isUpdateMetadataOrRename?" << isUpdateMetadataOrRename
<< "isFileDownloadOrDirectory?" << isFileDownloadOrDirectory
<< "_dirItem?" << _dirItem
<< "_dirParentItem?" << _dirParentItem
<< "item->_size:" << item->_size
<< "_folderQuota.bytesAvailable:" << _folderQuota.bytesAvailable
<< "_folderQuota.bytesUsed:" << _folderQuota.bytesUsed;

if (item->_size == 0 || isTypeChange || isFileDownloadOrDirectory || isUpdateMetadataOrRename) {
qCDebug(lcDisco) << "Returning unlimited free space (-3) for item quota.";
return unlimitedFreeSpace;
}

if (item->_instruction != CSYNC_INSTRUCTION_SYNC && item->_instruction != CSYNC_INSTRUCTION_NEW) {
return unlimitedFreeSpace;
if (serverEntry == FolderQuota::ServerEntry::Valid) {
qCDebug(lcDisco) << "Returning cached _folderQuota.bytesAvailable for item quota.";
return _folderQuota.bytesAvailable;
}

if (serverEntry == FolderQuota::ServerEntry::Valid || !_dirItem) {
return _folderQuota.bytesAvailable;
if (!_dirItem) {
qCDebug(lcDisco) << "Returning unlimited free space (-3) for item quota with no _dirItem.";
return unlimitedFreeSpace;
}

qCDebug(lcDisco) << "_dirItem->_folderQuota.bytesAvailable:" << _dirItem->_folderQuota.bytesAvailable;

SyncJournalFileRecord dirItemDbRecord;
if (_discoveryData->_statedb->getFileRecord(_dirItem->_file, &dirItemDbRecord) && dirItemDbRecord.isValid()) {
return dirItemDbRecord._folderQuota.bytesAvailable;
const auto dirDbBytesAvailable = dirItemDbRecord._folderQuota.bytesAvailable;
qCDebug(lcDisco) << "Returning for item quota db value dirItemDbRecord._folderQuota.bytesAvailable" << dirDbBytesAvailable;
return dirDbBytesAvailable;
}

qCDebug(lcDisco) << "Returning _dirItem->_folderQuota.bytesAvailable for item quota.";
return _dirItem->_folderQuota.bytesAvailable;
}

Expand Down Expand Up @@ -2254,7 +2271,9 @@
Q_ASSERT(_dirItem->_e2eEncryptionStatus != SyncFileItem::EncryptionStatus::NotEncrypted);
_discoveryData->_anotherSyncNeeded = !alreadyDownloaded && serverJob->encryptedMetadataNeedUpdate();
}
qCInfo(lcDisco) << "serverJob has finished for folder:" << _dirItem->_file << " and it has _isFileDropDetected:" << _dirItem->_isFileDropDetected;
qCDebug(lcDisco) << "serverJob has finished for folder:" << _dirItem->_file << " and it has _isFileDropDetected:" << _dirItem->_isFileDropDetected
<< "with quota bytesUsed:" << _dirItem->_folderQuota.bytesUsed
<< "bytesAvailable:" << _dirItem->_folderQuota.bytesAvailable;
}
_discoveryData->_currentlyActiveJobs--;
_pendingAsyncJobs--;
Expand Down Expand Up @@ -2296,6 +2315,9 @@

void ProcessDirectoryJob::setFolderQuota(const FolderQuota &folderQuota)
{
qCDebug(lcDisco) << "Setting quota for folder" << _discoveryData->_localDir + _currentFolder._local
<< "bytes used:" << folderQuota.bytesUsed
<< "bytes available:" << folderQuota.bytesAvailable;
_folderQuota.bytesUsed = folderQuota.bytesUsed;
_folderQuota.bytesAvailable = folderQuota.bytesAvailable;
}
Expand Down
14 changes: 9 additions & 5 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand Down Expand Up @@ -590,7 +590,7 @@
}
}

void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(const QString &file, const QMap<QString, QString> &map)

Check warning on line 593 in src/libsync/discoveryphase.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/discoveryphase.cpp:593:35 [readability-function-cognitive-complexity]

function 'directoryListingIteratedSlot' has cognitive complexity of 26 (threshold 25)
{
if (!_ignoredFirst) {
// The first entry is for the folder itself, we should process it differently.
Expand Down Expand Up @@ -624,21 +624,25 @@
}

// all folders will contain both
if (map.contains(FolderQuota::usedBytesC) && map.contains(FolderQuota::availableBytesC)) {
if (map.contains(FolderQuota::usedBytesC) && map.contains(FolderQuota::availableBytesC)) {
_folderQuota = {map.value(FolderQuota::usedBytesC).toLongLong(),
map.value(FolderQuota::availableBytesC).toLongLong()};
qCWarning(lcDiscovery) << "Setting quota for" << file
<< "bytesUsed:" << _folderQuota.bytesUsed
<< "bytesAvailable:" << _folderQuota.bytesAvailable;
emit setfolderQuota(_folderQuota);

Check warning on line 633 in src/libsync/discoveryphase.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/discoveryphase.cpp:633:18 [cppcoreguidelines-init-variables]

variable 'setfolderQuota' is not initialized
}
} else {
RemoteInfo result;
int slash = file.lastIndexOf('/');
result.name = file.mid(slash + 1);
result.size = -1;
if (map.contains(FolderQuota::usedBytesC)) {
result.folderQuota.bytesUsed = map.value(FolderQuota::usedBytesC).toLongLong();
}
if (map.contains(FolderQuota::availableBytesC)) {
if (map.contains(FolderQuota::usedBytesC) && map.contains(FolderQuota::availableBytesC)) {
result.folderQuota.bytesAvailable = map.value(FolderQuota::availableBytesC).toLongLong();
result.folderQuota.bytesUsed = map.value(FolderQuota::usedBytesC).toLongLong();
qCWarning(lcDiscovery) << "Setting quota for" << file
<< "bytesUsed:" << result.folderQuota.bytesUsed
<< "bytesAvailable:" << result.folderQuota.bytesAvailable;
}
propertyMapToRemoteInfo(map,
_account->serverHasMountRootProperty() ? RemotePermissions::MountedPermissionAlgorithm::UseMountRootProperty : RemotePermissions::MountedPermissionAlgorithm::WildGuessMountedSubProperty,
Expand Down
Loading