Skip to content

Commit 99a4838

Browse files
authored
- clean up deleted profile synchronizers (microsoft#165713)
- check if profile synchronizer matches collection
1 parent d3611df commit 99a4838

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/vs/platform/userDataSync/common/userDataSyncService.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
225225
const profileSynchronizer = this.getOrCreateActiveProfileSynchronizer(profile, syncProfile);
226226
this._syncErrors.push(...await this.syncProfile(profileSynchronizer, manifest, merge, executionId, token));
227227
}
228+
// Dispose & Delete profile synchronizers which do not exist anymore
229+
for (const [key, profileSynchronizerItem] of this.activeProfileSynchronizers.entries()) {
230+
if (this.userDataProfilesService.profiles.some(p => p.id === profileSynchronizerItem[0].profile.id)) {
231+
continue;
232+
}
233+
profileSynchronizerItem[1].dispose();
234+
this.activeProfileSynchronizers.delete(key);
235+
}
228236
}
229237

230238
private async applyManualSync(manifest: IUserDataManifest | null, executionId: string, token: CancellationToken): Promise<void> {
@@ -472,6 +480,12 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
472480

473481
getOrCreateActiveProfileSynchronizer(profile: IUserDataProfile, syncProfile: ISyncUserDataProfile | undefined): ProfileSynchronizer {
474482
let activeProfileSynchronizer = this.activeProfileSynchronizers.get(profile.id);
483+
if (activeProfileSynchronizer && activeProfileSynchronizer[0].collection !== syncProfile?.collection) {
484+
this.logService.error('Profile synchronizer collection does not match with the remote sync profile collection');
485+
activeProfileSynchronizer[1].dispose();
486+
activeProfileSynchronizer = undefined;
487+
this.activeProfileSynchronizers.delete(profile.id);
488+
}
475489
if (!activeProfileSynchronizer) {
476490
const disposables = new DisposableStore();
477491
const profileSynchronizer = disposables.add(this.instantiationService.createInstance(ProfileSynchronizer, profile, syncProfile?.collection));
@@ -525,11 +539,9 @@ class ProfileSynchronizer extends Disposable {
525539
private _onDidChangeConflicts = this._register(new Emitter<IUserDataSyncResourceConflicts[]>());
526540
readonly onDidChangeConflicts = this._onDidChangeConflicts.event;
527541

528-
get profile(): IUserDataProfile { return this._profile; }
529-
530542
constructor(
531-
private _profile: IUserDataProfile,
532-
private readonly collection: string | undefined,
543+
readonly profile: IUserDataProfile,
544+
readonly collection: string | undefined,
533545
@IUserDataSyncEnablementService private readonly userDataSyncEnablementService: IUserDataSyncEnablementService,
534546
@IInstantiationService private readonly instantiationService: IInstantiationService,
535547
@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService,
@@ -568,7 +580,7 @@ class ProfileSynchronizer extends Disposable {
568580
return;
569581
}
570582
if (syncResource === SyncResource.Profiles) {
571-
if (!this._profile.isDefault) {
583+
if (!this.profile.isDefault) {
572584
return;
573585
}
574586
if (!this.userDataProfilesService.isEnabled()) {
@@ -608,13 +620,13 @@ class ProfileSynchronizer extends Disposable {
608620

609621
createSynchronizer(syncResource: SyncResource): IUserDataSynchroniser & IDisposable {
610622
switch (syncResource) {
611-
case SyncResource.Settings: return this.instantiationService.createInstance(SettingsSynchroniser, this._profile, this.collection);
612-
case SyncResource.Keybindings: return this.instantiationService.createInstance(KeybindingsSynchroniser, this._profile, this.collection);
613-
case SyncResource.Snippets: return this.instantiationService.createInstance(SnippetsSynchroniser, this._profile, this.collection);
614-
case SyncResource.Tasks: return this.instantiationService.createInstance(TasksSynchroniser, this._profile, this.collection);
615-
case SyncResource.GlobalState: return this.instantiationService.createInstance(GlobalStateSynchroniser, this._profile, this.collection);
616-
case SyncResource.Extensions: return this.instantiationService.createInstance(ExtensionsSynchroniser, this._profile, this.collection);
617-
case SyncResource.Profiles: return this.instantiationService.createInstance(UserDataProfilesManifestSynchroniser, this._profile, this.collection);
623+
case SyncResource.Settings: return this.instantiationService.createInstance(SettingsSynchroniser, this.profile, this.collection);
624+
case SyncResource.Keybindings: return this.instantiationService.createInstance(KeybindingsSynchroniser, this.profile, this.collection);
625+
case SyncResource.Snippets: return this.instantiationService.createInstance(SnippetsSynchroniser, this.profile, this.collection);
626+
case SyncResource.Tasks: return this.instantiationService.createInstance(TasksSynchroniser, this.profile, this.collection);
627+
case SyncResource.GlobalState: return this.instantiationService.createInstance(GlobalStateSynchroniser, this.profile, this.collection);
628+
case SyncResource.Extensions: return this.instantiationService.createInstance(ExtensionsSynchroniser, this.profile, this.collection);
629+
case SyncResource.Profiles: return this.instantiationService.createInstance(UserDataProfilesManifestSynchroniser, this.profile, this.collection);
618630
}
619631
}
620632

0 commit comments

Comments
 (0)