You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-06 09:19:22 +02:00
Desktop: Fixed clock sync logic when creating new sync target
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import LockHandler from 'lib/services/synchronizer/LockHandler';
|
import LockHandler from 'lib/services/synchronizer/LockHandler';
|
||||||
import MigrationHandler from 'lib/services/synchronizer/MigrationHandler';
|
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:
|
// To create a sync target snapshot for the current syncVersion:
|
||||||
// - In test-utils, set syncTargetName_ to "filesystem"
|
// - In test-utils, set syncTargetName_ to "filesystem"
|
||||||
@@ -70,6 +71,14 @@ describe('synchronizer_MigrationHandler', function() {
|
|||||||
done();
|
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 () => {
|
it('should not allow syncing if the sync target is out-dated', asyncTest(async () => {
|
||||||
await synchronizer().start();
|
await synchronizer().start();
|
||||||
await fileApi().put('info.json', `{"version":${Setting.value('syncVersion') - 1}}`);
|
await fileApi().put('info.json', `{"version":${Setting.value('syncVersion') - 1}}`);
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ const KeychainServiceDriver = require('lib/services/keychain/KeychainServiceDriv
|
|||||||
const KeychainServiceDriverDummy = require('lib/services/keychain/KeychainServiceDriver.dummy').default;
|
const KeychainServiceDriverDummy = require('lib/services/keychain/KeychainServiceDriver.dummy').default;
|
||||||
const md5 = require('md5');
|
const md5 = require('md5');
|
||||||
const S3 = require('aws-sdk/clients/s3');
|
const S3 = require('aws-sdk/clients/s3');
|
||||||
|
const { Dirnames } = require('lib/services/synchronizer/utils/types');
|
||||||
|
|
||||||
const databases_ = [];
|
const databases_ = [];
|
||||||
let synchronizers_ = [];
|
let synchronizers_ = [];
|
||||||
@@ -438,6 +439,7 @@ async function initFileApi() {
|
|||||||
|
|
||||||
fileApi.setLogger(logger);
|
fileApi.setLogger(logger);
|
||||||
fileApi.setSyncTargetId(syncTargetId_);
|
fileApi.setSyncTargetId(syncTargetId_);
|
||||||
|
fileApi.setTempDirName(Dirnames.Temp);
|
||||||
fileApi.requestRepeatCount_ = isNetworkSyncTarget_ ? 1 : 0;
|
fileApi.requestRepeatCount_ = isNetworkSyncTarget_ ? 1 : 0;
|
||||||
|
|
||||||
fileApis_[syncTargetId_] = fileApi;
|
fileApis_[syncTargetId_] = fileApi;
|
||||||
|
|||||||
@@ -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
|
// 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
|
// 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.
|
// 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) => {
|
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)
|
// If it's on macOS, the app is completely closed only if the user chooses to close the app (willQuitApp_ will be true)
|
||||||
|
|||||||
@@ -90,9 +90,11 @@ export default class MigrationHandler extends BaseService {
|
|||||||
// it the lock handler will break. So we create the directory now.
|
// 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
|
// 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.
|
// 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) {
|
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.Locks);
|
||||||
|
await this.api_.mkdir(Dirnames.Temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger().info('MigrationHandler: Acquiring exclusive lock');
|
this.logger().info('MigrationHandler: Acquiring exclusive lock');
|
||||||
|
|||||||
@@ -305,6 +305,8 @@ class Synchronizer {
|
|||||||
let syncLock = null;
|
let syncLock = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.api().setTempDirName(Dirnames.Temp);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const syncTargetInfo = await this.migrationHandler().checkCanSync();
|
const syncTargetInfo = await this.migrationHandler().checkCanSync();
|
||||||
|
|
||||||
@@ -321,8 +323,6 @@ class Synchronizer {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.api().setTempDirName(Dirnames.Temp);
|
|
||||||
|
|
||||||
syncLock = await this.lockHandler().acquireLock('sync', this.appType_, this.clientId_);
|
syncLock = await this.lockHandler().acquireLock('sync', this.appType_, this.clientId_);
|
||||||
|
|
||||||
this.lockHandler().startAutoLockRefresh(syncLock, (error) => {
|
this.lockHandler().startAutoLockRefresh(syncLock, (error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user