* fix syncing profiles (#209336)

fix #208710

* bailout if profile with same name exists already

* make it sync
This commit is contained in:
Sandeep Somavarapu 2024-04-02 15:03:22 +02:00 committed by GitHub
parent 8d1ecd7b94
commit 3289aba2b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 24 deletions

View file

@ -335,7 +335,7 @@ export class UserDataProfilesService extends Disposable implements IUserDataProf
try { try {
const existing = this.profiles.find(p => p.name === name || p.id === id); const existing = this.profiles.find(p => p.name === name || p.id === id);
if (existing) { 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); const profile = toUserDataProfile(id, name, joinPath(this.profilesHome, id), this.profilesCacheHome, options, this.defaultProfile);

View file

@ -187,34 +187,26 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
if (localChange !== Change.None) { if (localChange !== Change.None) {
await this.backupLocal(stringifyLocalProfiles(this.getLocalUserDataProfiles(), false)); await this.backupLocal(stringifyLocalProfiles(this.getLocalUserDataProfiles(), false));
const promises: Promise<any>[] = []; await Promise.all(local.removed.map(async profile => {
for (const profile of local.added) { this.logService.trace(`${this.syncResourceLogLabel}: Removing '${profile.name}' profile...`);
promises.push((async () => { await this.userDataProfilesService.removeProfile(profile);
this.logService.trace(`${this.syncResourceLogLabel}: Creating '${profile.name}' profile...`); this.logService.info(`${this.syncResourceLogLabel}: Removed profile '${profile.name}'.`);
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.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 });
for (const profile of local.removed) { this.logService.info(`${this.syncResourceLogLabel}: Created profile '${profile.name}'.`);
promises.push((async () => { }));
this.logService.trace(`${this.syncResourceLogLabel}: Removing '${profile.name}' profile...`); await Promise.all(local.updated.map(async 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); const localProfile = this.userDataProfilesService.profiles.find(p => p.id === profile.id);
if (localProfile) { if (localProfile) {
promises.push((async () => { this.logService.trace(`${this.syncResourceLogLabel}: Updating '${profile.name}' profile...`);
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 });
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.info(`${this.syncResourceLogLabel}: Updated profile '${profile.name}'.`);
})());
} else { } else {
this.logService.info(`${this.syncResourceLogLabel}: Could not find profile with id '${profile.id}' to update.`); this.logService.info(`${this.syncResourceLogLabel}: Could not find profile with id '${profile.id}' to update.`);
} }
} }));
await Promise.all(promises);
} }
if (remoteChange !== Change.None) { if (remoteChange !== Change.None) {