From 0f1156ab9c23b6a0adf5f96b44efc1cd95b6bc6e Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 11 Sep 2020 23:33:34 +0100 Subject: [PATCH] Desktop: Fixed clock sync logic when creating new sync target --- CliClient/tests/synchronizer_MigrationHandler.ts | 9 +++++++++ CliClient/tests/test-utils.js | 2 ++ ElectronClient/ElectronAppWrapper.js | 12 +++++++++++- .../lib/services/synchronizer/MigrationHandler.ts | 4 +++- ReactNativeClient/lib/synchronizer.js | 4 ++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CliClient/tests/synchronizer_MigrationHandler.ts b/CliClient/tests/synchronizer_MigrationHandler.ts index b16fa51330..0b9d2495da 100644 --- a/CliClient/tests/synchronizer_MigrationHandler.ts +++ b/CliClient/tests/synchronizer_MigrationHandler.ts @@ -1,5 +1,6 @@ import LockHandler from 'lib/services/synchronizer/LockHandler'; import MigrationHandler from 'lib/services/synchronizer/MigrationHandler'; +import { Dirnames } from 'lib/services/synchronizer/utils/types'; // To create a sync target snapshot for the current syncVersion: // - In test-utils, set syncTargetName_ to "filesystem" @@ -70,6 +71,14 @@ describe('synchronizer_MigrationHandler', function() { done(); }); + it('should init a new sync target', asyncTest(async () => { + // Check that basic folders "locks" and "temp" are created for new sync targets. + await migrationHandler().upgrade(1); + const result = await fileApi().list(); + expect(result.items.filter((i:any) => i.path === Dirnames.Locks).length).toBe(1); + expect(result.items.filter((i:any) => i.path === Dirnames.Temp).length).toBe(1); + }), specTimeout); + it('should not allow syncing if the sync target is out-dated', asyncTest(async () => { await synchronizer().start(); await fileApi().put('info.json', `{"version":${Setting.value('syncVersion') - 1}}`); diff --git a/CliClient/tests/test-utils.js b/CliClient/tests/test-utils.js index 127419c7bc..0cb8001dec 100644 --- a/CliClient/tests/test-utils.js +++ b/CliClient/tests/test-utils.js @@ -50,6 +50,7 @@ const KeychainServiceDriver = require('lib/services/keychain/KeychainServiceDriv const KeychainServiceDriverDummy = require('lib/services/keychain/KeychainServiceDriver.dummy').default; const md5 = require('md5'); const S3 = require('aws-sdk/clients/s3'); +const { Dirnames } = require('lib/services/synchronizer/utils/types'); const databases_ = []; let synchronizers_ = []; @@ -438,6 +439,7 @@ async function initFileApi() { fileApi.setLogger(logger); fileApi.setSyncTargetId(syncTargetId_); + fileApi.setTempDirName(Dirnames.Temp); fileApi.requestRepeatCount_ = isNetworkSyncTarget_ ? 1 : 0; fileApis_[syncTargetId_] = fileApi; diff --git a/ElectronClient/ElectronAppWrapper.js b/ElectronClient/ElectronAppWrapper.js index 89c42cdbd3..1b052dbb7c 100644 --- a/ElectronClient/ElectronAppWrapper.js +++ b/ElectronClient/ElectronAppWrapper.js @@ -105,7 +105,17 @@ class ElectronAppWrapper { // Waiting for one of the ready events might work but they might not be triggered if there's an error, so // the easiest is to use a timeout. Keep in mind that if you get a white window on Windows it might be due // to this line though. - if (debugEarlyBugs) setTimeout(() => this.win_.webContents.openDevTools(), 3000); + if (debugEarlyBugs) { + setTimeout(() => { + try { + this.win_.webContents.openDevTools(); + } catch (error) { + // This will throw an exception "Object has been destroyed" if the app is closed + // in less that the timeout interval. It can be ignored. + console.warn('Error opening dev tools', error); + } + }, 3000); + } this.win_.on('close', (event) => { // If it's on macOS, the app is completely closed only if the user chooses to close the app (willQuitApp_ will be true) diff --git a/ReactNativeClient/lib/services/synchronizer/MigrationHandler.ts b/ReactNativeClient/lib/services/synchronizer/MigrationHandler.ts index f8a8dea600..06d09f1f47 100644 --- a/ReactNativeClient/lib/services/synchronizer/MigrationHandler.ts +++ b/ReactNativeClient/lib/services/synchronizer/MigrationHandler.ts @@ -90,9 +90,11 @@ export default class MigrationHandler extends BaseService { // it the lock handler will break. So we create the directory now. // Also if the sync target version is 0, it means it's a new one so we need the // lock folder first before doing anything else. + // Temp folder is needed too to get remoteDate() call to work. if (syncTargetInfo.version === 0 || syncTargetInfo.version === 1) { - this.logger().info('MigrationHandler: Sync target version is 0 or 1 - creating "locks" directory:', syncTargetInfo); + this.logger().info('MigrationHandler: Sync target version is 0 or 1 - creating "locks" and "temp" directory:', syncTargetInfo); await this.api_.mkdir(Dirnames.Locks); + await this.api_.mkdir(Dirnames.Temp); } this.logger().info('MigrationHandler: Acquiring exclusive lock'); diff --git a/ReactNativeClient/lib/synchronizer.js b/ReactNativeClient/lib/synchronizer.js index 465997d674..0096a2d8d3 100644 --- a/ReactNativeClient/lib/synchronizer.js +++ b/ReactNativeClient/lib/synchronizer.js @@ -305,6 +305,8 @@ class Synchronizer { let syncLock = null; try { + this.api().setTempDirName(Dirnames.Temp); + try { const syncTargetInfo = await this.migrationHandler().checkCanSync(); @@ -321,8 +323,6 @@ class Synchronizer { throw error; } - this.api().setTempDirName(Dirnames.Temp); - syncLock = await this.lockHandler().acquireLock('sync', this.appType_, this.clientId_); this.lockHandler().startAutoLockRefresh(syncLock, (error) => {