Fix: Delay log folder creation until primary instance is confirmed

Move log folder (logsHome) creation from initServices() to after
claimInstance() succeeds. This prevents secondary instances from
creating empty log folders when they simply connect to the primary
instance and exit.

Fixes #250334

Co-authored-by: sandy081 <10746682+sandy081@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-16 16:50:07 +00:00
parent bea16329fd
commit d400c15161

View File

@@ -134,6 +134,10 @@ class CodeMain {
logService.warn(`app#startup(): Error writing main lockfile: ${err.stack}`);
});
// Create logs folder now that we are the primary instance
// (https://github.com/microsoft/vscode/issues/250334)
await promises.mkdir(environmentMainService.logsHome.with({ scheme: Schemas.file }).fsPath, { recursive: true });
// Delay creation of spdlog for perf reasons (https://github.com/microsoft/vscode/issues/72906)
bufferLogger.logger = loggerService.createLogger('main', { name: localize('mainLog', "Main") });
@@ -268,10 +272,11 @@ class CodeMain {
await Promises.settled<unknown>([
// Environment service (paths)
// Note: logsHome is not created here to avoid creating empty log folders
// for secondary instances. It is created later after claimInstance succeeds.
Promise.all<string | undefined>([
this.allowWindowsUNCPath(environmentMainService.extensionsPath), // enable extension paths on UNC drives...
environmentMainService.codeCachePath, // ...other user-data-derived paths should already be enlisted from `main.js`
environmentMainService.logsHome.with({ scheme: Schemas.file }).fsPath,
userDataProfilesMainService.defaultProfile.globalStorageHome.with({ scheme: Schemas.file }).fsPath,
environmentMainService.workspaceStorageHome.with({ scheme: Schemas.file }).fsPath,
environmentMainService.localHistoryHome.with({ scheme: Schemas.file }).fsPath,