diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 1ff9c5f080ff1..588d0dc9037a7 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -756,13 +756,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it 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 { @@ -1085,23 +1080,45 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it 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; } @@ -2254,7 +2271,9 @@ DiscoverySingleDirectoryJob *ProcessDirectoryJob::startAsyncServerQuery() 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--; @@ -2296,6 +2315,9 @@ DiscoverySingleDirectoryJob *ProcessDirectoryJob::startAsyncServerQuery() 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; } diff --git a/src/libsync/discoveryphase.cpp b/src/libsync/discoveryphase.cpp index 16e7c8822e0bf..83b725143decf 100644 --- a/src/libsync/discoveryphase.cpp +++ b/src/libsync/discoveryphase.cpp @@ -624,9 +624,12 @@ void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(const QString &fi } // 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); } } else { @@ -634,11 +637,12 @@ void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(const QString &fi 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,