1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

All: Added fail-safe to prevent data from being wiped out when the sync target is empty

This commit is contained in:
Laurent Cozic
2019-09-25 18:40:04 +00:00
parent 3e5a9cdb97
commit 348efdd7b6
5 changed files with 32 additions and 2 deletions

View File

@ -247,6 +247,13 @@ async function basicDelta(path, getDirStatFn, options) {
});
newContext.statIdsCache = newContext.statsCache.filter(item => BaseItem.isSystemPath(item.path)).map(item => BaseItem.pathToId(item.path));
newContext.statIdsCache.sort(); // Items must be sorted to use binary search below
// At this point statIdsCache contains the list of all the item IDs on the sync target.
// If it's empty, it's most likely a configuration error or bug. For example, if the
// user moves their Nextcloud directory, or if a network drive gets disconnected and
// returns an empty dir instead of an error. In that case, we don't wipe out the user
// data, unless they have switched off the fail-safe.
if (options.wipeOutFailSafe && !newContext.statIdsCache.length) throw new JoplinError('Fail-safe: The delta operation was interrupted because the sync target appears to be empty. To override this behaviour disable the "Wipe out fail-safe" option in the settings.', 'failSafe');
}
let output = [];