From ab8b492e66f732f4ad16942e9cdacd1e62fecc73 Mon Sep 17 00:00:00 2001 From: Gilles Filippini <pini@debian.org> Date: Tue, 11 May 2021 10:49:01 +0200 Subject: [PATCH] fix(sync): when called with --only-peers When 'sync' is called with option '--only-peers', the path to function 'RemoteSynchronizer.getPeers()' is not the same as the default. In this case we need to ensure that 'init()' was properly called and proceed without a watcher. --- app/modules/crawler/lib/sync/RemoteSynchronizer.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/modules/crawler/lib/sync/RemoteSynchronizer.ts b/app/modules/crawler/lib/sync/RemoteSynchronizer.ts index f173627cc..e9a759fc3 100644 --- a/app/modules/crawler/lib/sync/RemoteSynchronizer.ts +++ b/app/modules/crawler/lib/sync/RemoteSynchronizer.ts @@ -382,16 +382,23 @@ export class RemoteSynchronizer extends AbstractSynchronizer { } async syncPeers(fullSync: boolean, to?: number): Promise<void> { + if (!this.node) { + await this.init(); + } const peers = await this.node.getPeers(); for (let i = 0; i < peers.length; i++) { const peer = PeerDTO.fromJSONObject(peers[i]); - this.watcher.writeStatus("Peer " + peer.pubkey); - this.watcher.peersPercent(Math.ceil((i / peers.length) * 100)); + if (this.watcher) { + this.watcher.writeStatus("Peer " + peer.pubkey); + this.watcher.peersPercent(Math.ceil((i / peers.length) * 100)); + } try { await this.PeeringService.submitP(DBPeer.fromPeerDTO(peer)); } catch (e) {} } - this.watcher.peersPercent(100); + if (this.watcher) { + this.watcher.peersPercent(100); + } } async syncSandbox(): Promise<void> { -- GitLab