From 7f3f074d74067816a554ee13ad57138dfe38c238 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 24 Mar 2020 13:10:59 +0100 Subject: [PATCH] fix merging --- .../platform/userDataSync/common/globalStateMerge.ts | 12 ++++++------ .../platform/userDataSync/common/globalStateSync.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/userDataSync/common/globalStateMerge.ts b/src/vs/platform/userDataSync/common/globalStateMerge.ts index f40cfb12729..edb15a95b0d 100644 --- a/src/vs/platform/userDataSync/common/globalStateMerge.ts +++ b/src/vs/platform/userDataSync/common/globalStateMerge.ts @@ -53,19 +53,19 @@ export function merge(localStorage: IStringDictionary, remoteStor } } - // Updated in Remote - for (const key of values(baseToRemote.updated)) { + // Updated in local + for (const key of values(baseToLocal.updated)) { if (!baseToRemote.updated.has(key) || !baseToRemote.removed.has(key)) { const remoteValue = remote[key]; const localValue = localStorage[key]; if (localValue.version >= remoteValue.version) { - remote[key] = remoteValue; + remote[key] = localValue; } } } - // Removed in remote - for (const key of values(baseToRemote.removed)) { + // Removed in local + for (const key of values(baseToLocal.removed)) { if (!baseToRemote.updated.has(key)) { const remoteValue = remote[key]; const storageKey = storageKeys.filter(storageKey => storageKey.key === key)[0]; @@ -75,7 +75,7 @@ export function merge(localStorage: IStringDictionary, remoteStor } } - return { local, remote: areSame(remote, remoteStorage) ? null : remoteStorage }; + return { local, remote: areSame(remote, remoteStorage) ? null : remote }; } function compare(from: IStringDictionary, to: IStringDictionary): { added: Set, removed: Set, updated: Set } { diff --git a/src/vs/platform/userDataSync/common/globalStateSync.ts b/src/vs/platform/userDataSync/common/globalStateSync.ts index ec0669f1f5d..f1d8a26a6a3 100644 --- a/src/vs/platform/userDataSync/common/globalStateSync.ts +++ b/src/vs/platform/userDataSync/common/globalStateSync.ts @@ -163,7 +163,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs private async getPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null): Promise { const remoteGlobalState: IGlobalState = remoteUserData.syncData ? JSON.parse(remoteUserData.syncData.content) : null; - const lastSyncGlobalState = lastSyncUserData && lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null; + const lastSyncGlobalState: IGlobalState = lastSyncUserData && lastSyncUserData.syncData ? JSON.parse(lastSyncUserData.syncData.content) : null; const localGloablState = await this.getLocalGlobalState(); @@ -173,7 +173,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs this.logService.trace(`${this.syncResourceLogLabel}: Remote ui state does not exist. Synchronizing ui state for the first time.`); } - const { local, remote } = merge(localGloablState.storage, remoteGlobalState.storage, lastSyncGlobalState, this.storageKeysSyncRegistryService.storageKeys); + const { local, remote } = merge(localGloablState.storage, remoteGlobalState.storage, lastSyncGlobalState ? lastSyncGlobalState.storage : null, this.storageKeysSyncRegistryService.storageKeys); return { local, remote, remoteUserData, localUserData: localGloablState, lastSyncUserData }; } @@ -198,7 +198,7 @@ export class GlobalStateSynchroniser extends AbstractSynchroniser implements IUs if (hasRemoteChanged) { // update remote this.logService.trace(`${this.syncResourceLogLabel}: Updating remote ui state...`); - const content = JSON.stringify(remote); + const content = JSON.stringify({ storage: remote }); remoteUserData = await this.updateRemoteUserData(content, forcePush ? null : remoteUserData.ref); this.logService.info(`${this.syncResourceLogLabel}: Updated remote ui state`); } -- GitLab