feat-logs-home.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. diff --git a/src/vs/platform/environment/common/environment.ts b/src/vs/platform/environment/common/environment.ts
  2. index 4a14c83..59c963b 100644
  3. --- a/src/vs/platform/environment/common/environment.ts
  4. +++ b/src/vs/platform/environment/common/environment.ts
  5. @@ -137,2 +137,3 @@ export interface INativeEnvironmentService extends IEnvironmentService {
  6. userDataPath: string;
  7. + userStatePath: string;
  8. diff --git a/src/vs/platform/environment/common/environmentService.ts b/src/vs/platform/environment/common/environmentService.ts
  9. index 535132f..edd76bc 100644
  10. --- a/src/vs/platform/environment/common/environmentService.ts
  11. +++ b/src/vs/platform/environment/common/environmentService.ts
  12. @@ -28,2 +28,4 @@ export interface INativeEnvironmentPaths {
  13. + userStateDir: string;
  14. +
  15. /**
  16. @@ -54,2 +56,5 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
  17. + @memoize
  18. + get userStatePath(): string { return this.paths.userStateDir; }
  19. +
  20. @memoize
  21. @@ -75,3 +80,3 @@ export abstract class AbstractNativeEnvironmentService implements INativeEnviron
  22. const key = toLocalISOString(new Date()).replace(/-|:|\.\d+Z$/g, '');
  23. - this.args.logsPath = join(this.userDataPath, 'logs', key);
  24. + this.args.logsPath = join(this.userStatePath, key);
  25. }
  26. diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts
  27. index ae9e7e1..3c6c6c5 100644
  28. --- a/src/vs/platform/environment/node/environmentService.ts
  29. +++ b/src/vs/platform/environment/node/environmentService.ts
  30. @@ -11,2 +11,3 @@ import { getUserDataPath } from './userDataPath.js';
  31. import { IProductService } from '../../product/common/productService.js';
  32. +import { getUserStatePath } from './userStatePath.js';
  33. @@ -18,3 +19,4 @@ export class NativeEnvironmentService extends AbstractNativeEnvironmentService {
  34. tmpDir: tmpdir(),
  35. - userDataDir: getUserDataPath(args, productService.nameShort)
  36. + userDataDir: getUserDataPath(args, productService.nameShort),
  37. + userStateDir: getUserStatePath(args, productService.nameShort)
  38. }, productService);
  39. diff --git a/src/vs/platform/environment/node/userStatePath.ts b/src/vs/platform/environment/node/userStatePath.ts
  40. new file mode 100644
  41. index 0000000..53f9e2f
  42. --- /dev/null
  43. +++ b/src/vs/platform/environment/node/userStatePath.ts
  44. @@ -0,0 +1,42 @@
  45. +import { homedir } from 'os';
  46. +import { NativeParsedArgs } from '../common/argv.js';
  47. +
  48. +import { resolve, isAbsolute, join } from 'path';
  49. +
  50. +const cwd = process.env['VSCODE_CWD'] || process.cwd();
  51. +
  52. +export function getUserStatePath(cliArgs: NativeParsedArgs, productName: string): string {
  53. + const userStatePath = doGetUserStatePath(cliArgs, productName);
  54. + const pathsToResolve = [userStatePath];
  55. +
  56. + if (!isAbsolute(userStatePath)) {
  57. + pathsToResolve.unshift(cwd);
  58. + }
  59. +
  60. + return resolve(...pathsToResolve);
  61. +}
  62. +
  63. +function doGetUserStatePath(cliArgs: NativeParsedArgs, productName: string): string {
  64. +
  65. + // 0. Running out of sources has a fixed productName
  66. + if (process.env['VSCODE_DEV']) {
  67. + productName = 'code-oss-dev';
  68. + }
  69. +
  70. + // 1. Support portable mode
  71. + const portablePath = process.env['VSCODE_PORTABLE'];
  72. + if (portablePath) {
  73. + return join(portablePath, 'user-state');
  74. + }
  75. +
  76. + // 2. Support global VSCODE_APPSTATE environment variable
  77. + let appStatePath = process.env['VSCODE_APPSTATE'];
  78. + if (appStatePath) {
  79. + return join(appStatePath, productName);
  80. + }
  81. +
  82. + // 4. Otherwise
  83. + appStatePath = process.env['XDG_STATE_HOME'] || join(homedir(), '.local', 'state');
  84. +
  85. + return join(appStatePath, productName);
  86. +}
  87. diff --git a/src/vs/platform/window/common/window.ts b/src/vs/platform/window/common/window.ts
  88. index fa297d1..839fd60 100644
  89. --- a/src/vs/platform/window/common/window.ts
  90. +++ b/src/vs/platform/window/common/window.ts
  91. @@ -443,2 +443,3 @@ export interface INativeWindowConfiguration extends IWindowConfiguration, Native
  92. userDataDir: string;
  93. + userStateDir: string;
  94. diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts
  95. index 117dfd2..6b0458b 100644
  96. --- a/src/vs/platform/windows/electron-main/windowsMainService.ts
  97. +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts
  98. @@ -1511,2 +1511,3 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
  99. userDataDir: this.environmentMainService.userDataPath,
  100. + userStateDir: this.environmentMainService.userStatePath,
  101. diff --git a/src/vs/workbench/services/environment/electron-browser/environmentService.ts b/src/vs/workbench/services/environment/electron-browser/environmentService.ts
  102. index 6cfa517..46286c6 100644
  103. --- a/src/vs/workbench/services/environment/electron-browser/environmentService.ts
  104. +++ b/src/vs/workbench/services/environment/electron-browser/environmentService.ts
  105. @@ -153,3 +153,3 @@ export class NativeWorkbenchEnvironmentService extends AbstractNativeEnvironment
  106. ) {
  107. - super(configuration, { homeDir: configuration.homeDir, tmpDir: configuration.tmpDir, userDataDir: configuration.userDataDir }, productService);
  108. + super(configuration, { homeDir: configuration.homeDir, tmpDir: configuration.tmpDir, userDataDir: configuration.userDataDir, userStateDir: configuration.userStateDir }, productService);
  109. }
  110. diff --git a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyBackupService.test.ts b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyBackupService.test.ts
  111. index 6b7307e..c74476a 100644
  112. --- a/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyBackupService.test.ts
  113. +++ b/src/vs/workbench/services/workingCopy/test/electron-browser/workingCopyBackupService.test.ts
  114. @@ -74,2 +74,3 @@ const TestNativeWindowConfiguration: INativeWindowConfiguration = {
  115. userDataDir: joinPath(homeDir, product.nameShort).fsPath,
  116. + userStateDir: joinPath(homeDir, product.nameShort).fsPath,
  117. profiles: { profile: NULL_PROFILE, all: [NULL_PROFILE], home: homeDir },