373
374
async createProfile(id: string, name: string, options?: IUserDataProfileOptions, workspaceIdentifier?: IAnyWorkspaceIdentifier): Promise<IUserDataProfile> {
375
>
const profile = await this.doCreateProfile(id, name, options, workspaceIdentifier);
userDataProfile.ts
376
>
377
>
return profile;
378
>
}
379
380
private async doCreateProfile(id: string, name: string, options?: IUserDataProfileOptions, workspaceIdentifier?: IAnyWorkspaceIdentifier): Promise<IUserDataProfile> {
382
throw new Error('Name of the profile is mandatory and must be of type `string`');
383
}
385
>
let profileCreationPromise = this.profileCreationPromises.get(name);
386
>
if (!profileCreationPromise) {
387
>
profileCreationPromise = (async () => {
388
>
try {
389
>
const existing = this.profiles.find(p => p.id === id || (id !== AGENTS_WINDOW_PROFILE_ID && !p.isTransient && !options?.transient && p.name === name));
390
>
if (existing) {
391
throw new Error(`Profile with ${name} name already exists`);
392
}
394
>
const workspace = workspaceIdentifier ? this.getWorkspace(workspaceIdentifier) : undefined;
395
>
if (URI.isUri(workspace)) {
396
options = { ...options, workspaces: [workspace] };
397
}
399
>
const profile = toUserDataProfile(
400
>
id,
401
>
name,
402
>
this.uriIdentityService.extUri.joinPath(this.profilesHome, ...(id === AGENTS_WINDOW_PROFILE_ID ? [SYSTEM_PROFILES_HOME, id] : [id])),
403
>
this.profilesCacheHome,
404
>
id === AGENTS_WINDOW_PROFILE_ID ? {} : options,
405
>
this.defaultProfile);
406
>
await this.fileService.createFolder(profile.location);
407
>
408
>
const joiners: Promise<void>[] = [];
409
>
this._onWillCreateProfile.fire({
410
>
profile,
411
>
join(promise) {
412
joiners.push(promise);
413
}
415
>
await Promises.settled(joiners);
416
>
417
>
if (workspace && !URI.isUri(workspace)) {
418
this.updateEmptyWindowAssociation(workspace, profile, !!profile.isTransient);
419
}
421
>
return this.profiles.find(p => p.id === profile.id) ?? profile;
422
>
} finally {
423
>
this.profileCreationPromises.delete(name);
424
>
}
425
>
})();
426
>
this.profileCreationPromises.set(name, profileCreationPromise);
427
>
}
428
>
return profileCreationPromise;
429
>
}
430
431
async updateProfile(profile: IUserDataProfile, options: IUserDataProfileUpdateOptions): Promise<IUserDataProfile> {