Skip to content

Commit

Permalink
Properly check folder size on server
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Jul 3, 2023
1 parent 5fc9b70 commit e0cf0c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
15 changes: 7 additions & 8 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,11 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
const auto sizeOnServer = isVirtualE2EePlaceholder ? serverEntry.size - Constants::e2EeTagSize : serverEntry.size;
const auto metaDataSizeNeedsUpdateForE2EeFilePlaceholder = isVirtualE2EePlaceholder && dbEntry._fileSize == serverEntry.size;

if (serverEntry.isDirectory) {
// Even if over quota, continue syncing as normal for now
_discoveryData->checkSelectiveSyncExistingFolder(path._server);
}

if (serverEntry.isDirectory != dbEntry.isDirectory()) {
// If the type of the entity changed, it's like NEW, but
// needs to delete the other entity first.
Expand All @@ -717,19 +722,12 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
item->_instruction = CSYNC_INSTRUCTION_SYNC;
item->_type = ItemTypeVirtualFileDownload;
} else if (dbEntry._etag != serverEntry.etag) {
const auto differingSize = sizeOnServer != item->_size;

item->_direction = SyncFileItem::Down;
item->_modtime = serverEntry.modtime;
item->_size = sizeOnServer;

if (serverEntry.isDirectory) {
ENFORCE(dbEntry.isDirectory());

if (differingSize) {
_discoveryData->checkSelectiveSyncExistingFolder(path._server, sizeOnServer);
}

item->_instruction = CSYNC_INSTRUCTION_UPDATE_METADATA;
} else if (!localEntry.isValid() && _queryLocal != ParentNotChanged) {
// Deleted locally, changed on server
Expand All @@ -742,7 +740,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
<< "serverEntry.isDirectory:" << serverEntry.isDirectory
<< "dbEntry.isDirectory:" << dbEntry.isDirectory();
}
} else if (dbEntry._modtime != serverEntry.modtime && localEntry.size == serverEntry.size && dbEntry._fileSize == serverEntry.size && dbEntry._etag == serverEntry.etag) {
} else if (dbEntry._modtime != serverEntry.modtime && localEntry.size == serverEntry.size && dbEntry._fileSize == serverEntry.size
&& dbEntry._etag == serverEntry.etag) {
item->_direction = SyncFileItem::Down;
item->_modtime = serverEntry.modtime;
item->_size = sizeOnServer;
Expand Down
11 changes: 8 additions & 3 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,20 @@ void DiscoveryPhase::checkSelectiveSyncNewFolder(const QString &path,
});
}

void DiscoveryPhase::checkSelectiveSyncExistingFolder(const QString &path, const qint64 folderSize)
void DiscoveryPhase::checkSelectiveSyncExistingFolder(const QString &path)
{
// TODO: Check for setting to obey big folder sync
// If no size limit is enforced, or if is in whitelist (explicitly allowed) or in blacklist (explicitly disallowed), do nothing.
if (!activeFolderSizeLimit() || findPathInList(_selectiveSyncWhiteList, path) || findPathInList(_selectiveSyncBlackList, path)) {
return;
} else if (folderSize >= _syncOptions._newBigFolderSizeLimit) { // If the folder is too big, notify the user and prompt for response.
emit existingFolderNowBig(path);
}

checkFolderSizeLimit(path, [this, path](const bool bigFolder) {
if (bigFolder) {
// Notify the user and prompt for response.
emit existingFolderNowBig(path);
}
});
}

/* Given a path on the remote, give the path as it is when the rename is done */
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class DiscoveryPhase : public QObject
const RemotePermissions rp,
const std::function<void(bool)> callback);

void checkSelectiveSyncExistingFolder(const QString &path, const qint64 folderSize);
void checkSelectiveSyncExistingFolder(const QString &path);

/** Given an original path, return the target path obtained when renaming is done.
*
Expand Down

0 comments on commit e0cf0c6

Please sign in to comment.