From 2bb8f811d1a1a621e755264c3211326d30653af8 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Sat, 30 Jun 2018 14:29:57 +0200 Subject: [PATCH] [fix] sync: FS sync failed when source and target archives where not the same --- app/modules/crawler/lib/sync/ChunkGetter.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/modules/crawler/lib/sync/ChunkGetter.ts b/app/modules/crawler/lib/sync/ChunkGetter.ts index 54b312eec..c6a41f873 100644 --- a/app/modules/crawler/lib/sync/ChunkGetter.ts +++ b/app/modules/crawler/lib/sync/ChunkGetter.ts @@ -165,15 +165,18 @@ export class ChunkGetter { handler.downloader = this.p2PDownloader // If ever the first call does not chains well, we try using P2P ;(handler as any).state = 'WAITING' i++ - } else if (handler.downloader !== this.fsDownloader) { - // Store the file to avoid re-downloading - if (this.localNumber <= 0 && chunk.length === CommonConstants.CONST_BLOCKS_CHUNK) { - await this.writeDAL.confDAL.coreFS.makeTree(this.syncStrategy.getCurrency()) - const content = { blocks: chunk.map((b:any) => DBBlock.fromBlockDTO(b)) } - await this.writeDAL.confDAL.coreFS.writeJSON(fileName, content) - } } else { logger.warn("Chunk #%s read from filesystem.", i) + let doWrite = handler.downloader !== this.fsDownloader + || !(await this.writeDAL.confDAL.coreFS.exists(fileName)) + if (doWrite) { + // Store the file to avoid re-downloading + if (this.localNumber <= 0 && chunk.length === CommonConstants.CONST_BLOCKS_CHUNK) { + await this.writeDAL.confDAL.coreFS.makeTree(this.syncStrategy.getCurrency()) + const content = { blocks: chunk.map((b:any) => DBBlock.fromBlockDTO(b)) } + await this.writeDAL.confDAL.coreFS.writeJSON(fileName, content) + } + } } if (chainsWell) { -- GitLab