From a7eb25e8a2f5e9ddcc23075c2d951675d0fd625a Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 2 Apr 2024 13:36:23 +0200 Subject: [PATCH 1/3] fix syncing profiles (#209336) fix #208710 --- .../common/userDataProfilesManifestSync.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts b/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts index 5a532c8bae2f6..5656877af5372 100644 --- a/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts +++ b/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts @@ -187,6 +187,11 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i if (localChange !== Change.None) { await this.backupLocal(stringifyLocalProfiles(this.getLocalUserDataProfiles(), false)); + await Promise.all(local.removed.map(async profile => { + this.logService.trace(`${this.syncResourceLogLabel}: Removing '${profile.name}' profile...`); + await this.userDataProfilesService.removeProfile(profile); + this.logService.info(`${this.syncResourceLogLabel}: Removed profile '${profile.name}'.`); + })); const promises: Promise[] = []; for (const profile of local.added) { promises.push((async () => { @@ -195,13 +200,6 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i this.logService.info(`${this.syncResourceLogLabel}: Created profile '${profile.name}'.`); })()); } - for (const profile of local.removed) { - promises.push((async () => { - this.logService.trace(`${this.syncResourceLogLabel}: Removing '${profile.name}' profile...`); - await this.userDataProfilesService.removeProfile(profile); - this.logService.info(`${this.syncResourceLogLabel}: Removed profile '${profile.name}'.`); - })()); - } for (const profile of local.updated) { const localProfile = this.userDataProfilesService.profiles.find(p => p.id === profile.id); if (localProfile) { From 741caa6f6c0119c2989da11f44a60e292a72b497 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 2 Apr 2024 14:45:14 +0200 Subject: [PATCH 2/3] bailout if profile with same name exists already --- src/vs/platform/userDataProfile/common/userDataProfile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/platform/userDataProfile/common/userDataProfile.ts b/src/vs/platform/userDataProfile/common/userDataProfile.ts index f18de2499cd39..769f5fd2536de 100644 --- a/src/vs/platform/userDataProfile/common/userDataProfile.ts +++ b/src/vs/platform/userDataProfile/common/userDataProfile.ts @@ -335,7 +335,7 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf try { const existing = this.profiles.find(p => p.name === name || p.id === id); if (existing) { - return existing; + throw new Error(`Profile with ${name} name already exists`); } const profile = toUserDataProfile(id, name, joinPath(this.profilesHome, id), this.profilesCacheHome, options, this.defaultProfile); From 3ac42e5f25a10f8d1162b9594d91bf6f55231eb9 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 2 Apr 2024 14:47:22 +0200 Subject: [PATCH 3/3] make it sync --- .../common/userDataProfilesManifestSync.ts | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts b/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts index 5656877af5372..13b099ee13e8c 100644 --- a/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts +++ b/src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts @@ -192,27 +192,21 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i await this.userDataProfilesService.removeProfile(profile); this.logService.info(`${this.syncResourceLogLabel}: Removed profile '${profile.name}'.`); })); - const promises: Promise[] = []; - for (const profile of local.added) { - promises.push((async () => { - this.logService.trace(`${this.syncResourceLogLabel}: Creating '${profile.name}' profile...`); - await this.userDataProfilesService.createProfile(profile.id, profile.name, { shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags }); - this.logService.info(`${this.syncResourceLogLabel}: Created profile '${profile.name}'.`); - })()); - } - for (const profile of local.updated) { + await Promise.all(local.added.map(async profile => { + this.logService.trace(`${this.syncResourceLogLabel}: Creating '${profile.name}' profile...`); + await this.userDataProfilesService.createProfile(profile.id, profile.name, { shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags }); + this.logService.info(`${this.syncResourceLogLabel}: Created profile '${profile.name}'.`); + })); + await Promise.all(local.updated.map(async profile => { const localProfile = this.userDataProfilesService.profiles.find(p => p.id === profile.id); if (localProfile) { - promises.push((async () => { - this.logService.trace(`${this.syncResourceLogLabel}: Updating '${profile.name}' profile...`); - await this.userDataProfilesService.updateProfile(localProfile, { name: profile.name, shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags }); - this.logService.info(`${this.syncResourceLogLabel}: Updated profile '${profile.name}'.`); - })()); + this.logService.trace(`${this.syncResourceLogLabel}: Updating '${profile.name}' profile...`); + await this.userDataProfilesService.updateProfile(localProfile, { name: profile.name, shortName: profile.shortName, icon: profile.icon, useDefaultFlags: profile.useDefaultFlags }); + this.logService.info(`${this.syncResourceLogLabel}: Updated profile '${profile.name}'.`); } else { this.logService.info(`${this.syncResourceLogLabel}: Could not find profile with id '${profile.id}' to update.`); } - } - await Promise.all(promises); + })); } if (remoteChange !== Change.None) {