From 5b65fae49d3f03d2ab77449682dfee86961d9e39 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 13 Nov 2019 18:54:54 +0000 Subject: [PATCH] All: Improved logging during sync to allow finding bugs more easily --- ReactNativeClient/lib/file-api.js | 27 +++++++++++++++++++++++++-- ReactNativeClient/lib/synchronizer.js | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ReactNativeClient/lib/file-api.js b/ReactNativeClient/lib/file-api.js index de3c2b61a..821ce8dc8 100644 --- a/ReactNativeClient/lib/file-api.js +++ b/ReactNativeClient/lib/file-api.js @@ -245,8 +245,15 @@ async function basicDelta(path, getDirStatFn, options) { const itemIds = await options.allItemIdsHandler(); if (!Array.isArray(itemIds)) throw new Error('Delta API not supported - local IDs must be provided'); + const logger = options && options.logger ? options.logger : new Logger(); + const context = basicDeltaContextFromOptions_(options); + if (context.timestamp > Date.now()) { + logger.warn(`BasicDelta: Context timestamp is greater than current time: ${context.timestamp}`); + logger.warn('BasicDelta: Sync will continue but it is likely that nothing will be synced'); + } + let newContext = { timestamp: context.timestamp, filesAtTimestamp: context.filesAtTimestamp.slice(), @@ -267,6 +274,13 @@ async function basicDelta(path, getDirStatFn, options) { let output = []; + const updateReport = { + timestamp: context.timestamp, + older: 0, + newer: 0, + equal: 0, + }; + // Find out which files have been changed since the last time. Note that we keep // both the timestamp of the most recent change, *and* the items that exactly match // this timestamp. This to handle cases where an item is modified while this delta @@ -281,16 +295,23 @@ async function basicDelta(path, getDirStatFn, options) { if (stat.isDir) continue; - if (stat.updated_time < context.timestamp) continue; + if (stat.updated_time < context.timestamp) { + updateReport.older++; + continue; + } // Special case for items that exactly match the timestamp if (stat.updated_time === context.timestamp) { - if (context.filesAtTimestamp.indexOf(stat.path) >= 0) continue; + if (context.filesAtTimestamp.indexOf(stat.path) >= 0) { + updateReport.equal++; + continue; + } } if (stat.updated_time > newContext.timestamp) { newContext.timestamp = stat.updated_time; newContext.filesAtTimestamp = []; + updateReport.newer++; } newContext.filesAtTimestamp.push(stat.path); @@ -299,6 +320,8 @@ async function basicDelta(path, getDirStatFn, options) { if (output.length >= outputLimit) break; } + logger.info(`BasicDelta: Report: ${JSON.stringify(updateReport)}`); + if (!newContext.deletedItemsProcessed) { // Find out which items have been deleted on the sync target by comparing the items // we have to the items on the target. diff --git a/ReactNativeClient/lib/synchronizer.js b/ReactNativeClient/lib/synchronizer.js index bc7f9e904..36f4373fc 100644 --- a/ReactNativeClient/lib/synchronizer.js +++ b/ReactNativeClient/lib/synchronizer.js @@ -598,6 +598,8 @@ class Synchronizer { }, wipeOutFailSafe: Setting.value('sync.wipeOutFailSafe'), + + logger: this.logger(), }); let remotes = listResult.items;