Skip to content

Commit 3d43c10

Browse files
committed
portable: check folder
1 parent 79fe01e commit 3d43c10

5 files changed

Lines changed: 35 additions & 39 deletions

File tree

src/cli.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ function getApplicationPath() {
2020
}
2121
}
2222

23-
function getPortableDataPath() {
24-
return path.join(path.dirname(getApplicationPath()), product.portable);
23+
const portableDataName = product.portable || `${product.applicationName}-portable-data`;
24+
const portableDataPath = path.join(path.dirname(getApplicationPath()), portableDataName);
25+
const isPortable = fs.existsSync(portableDataPath);
26+
const portableTempPath = path.join(portableDataPath, 'tmp');
27+
const isTempPortable = isPortable && fs.existsSync(portableTempPath);
28+
29+
if (isPortable) {
30+
process.env['VSCODE_PORTABLE'] = portableDataPath;
31+
} else {
32+
delete process.env['VSCODE_PORTABLE'];
2533
}
2634

27-
if (product.portable && product.portableTemp) {
28-
const portablePath = getPortableDataPath();
29-
try { fs.mkdirSync(portablePath); } catch (err) { if (err.code !== 'EEXIST') { throw err; } }
30-
31-
const tmpdir = path.join(portablePath, 'tmp');
32-
try { fs.mkdirSync(tmpdir); } catch (err) { if (err.code !== 'EEXIST') { throw err; } }
33-
34-
process.env[process.platform === 'win32' ? 'TEMP' : 'TMPDIR'] = tmpdir;
35+
if (isTempPortable) {
36+
process.env[process.platform === 'win32' ? 'TEMP' : 'TMPDIR'] = portableTempPath;
3537
}
3638

3739
//#region Add support for using node_modules.asar

src/main.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@ function getApplicationPath() {
2727
}
2828
}
2929

30-
function getPortableDataPath() {
31-
return path.join(path.dirname(getApplicationPath()), product.portable);
30+
const portableDataName = product.portable || `${product.applicationName}-portable-data`;
31+
const portableDataPath = process.env['VSCODE_PORTABLE'] || path.join(path.dirname(getApplicationPath()), portableDataName);
32+
const isPortable = fs.existsSync(portableDataPath);
33+
const portableTempPath = path.join(portableDataPath, 'tmp');
34+
const isTempPortable = isPortable && fs.existsSync(portableTempPath);
35+
36+
if (isPortable) {
37+
process.env['VSCODE_PORTABLE'] = portableDataPath;
38+
} else {
39+
delete process.env['VSCODE_PORTABLE'];
3240
}
3341

34-
if (product.portable && product.portableTemp) {
35-
const portablePath = getPortableDataPath();
36-
try { fs.mkdirSync(portablePath); } catch (err) { if (err.code !== 'EEXIST') { throw err; } }
37-
38-
const tmpdir = path.join(portablePath, 'tmp');
39-
try { fs.mkdirSync(tmpdir); } catch (err) { if (err.code !== 'EEXIST') { throw err; } }
40-
41-
process.env[process.platform === 'win32' ? 'TEMP' : 'TMPDIR'] = tmpdir;
42+
if (isTempPortable) {
43+
process.env[process.platform === 'win32' ? 'TEMP' : 'TMPDIR'] = portableTempPath;
4244
}
4345

46+
console.log('portableDataPath', portableDataPath);
47+
console.log('isPortable', isPortable);
48+
4449
//#region Add support for using node_modules.asar
4550
(function () {
4651
const path = require('path');
@@ -377,8 +382,8 @@ function getNodeCachedDataDir() {
377382
//#endregion
378383

379384
function getUserDataPath() {
380-
if (product.portable) {
381-
return path.join(getPortableDataPath(), 'user-data');
385+
if (isPortable) {
386+
return path.join(portableDataPath, 'user-data');
382387
}
383388

384389
return path.resolve(args['user-data-dir'] || paths.getDefaultUserDataPath(process.platform));

src/vs/platform/environment/node/environmentService.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,10 @@ export class EnvironmentService implements IEnvironmentService {
8989
@memoize
9090
get userHome(): string { return os.homedir(); }
9191

92-
@memoize
93-
private get appPath(): string {
94-
if (process.env['VSCODE_DEV']) {
95-
return this.appRoot;
96-
} else if (process.platform === 'darwin') {
97-
return path.dirname(path.dirname(path.dirname(this.appRoot)));
98-
} else {
99-
return path.dirname(path.dirname(this.appRoot));
100-
}
101-
}
102-
10392
@memoize
10493
get userDataPath(): string {
105-
if (product.portable) {
106-
return path.join(path.dirname(this.appPath), product.portable, 'user-data');
94+
if (process.env['VSCODE_PORTABLE']) {
95+
return path.join(process.env['VSCODE_PORTABLE'], 'user-data');
10796
}
10897

10998
return parseUserDataDir(this._args, process);
@@ -151,8 +140,8 @@ export class EnvironmentService implements IEnvironmentService {
151140
return fromArgs;
152141
} else if (process.env['VSCODE_EXTENSIONS']) {
153142
return process.env['VSCODE_EXTENSIONS'];
154-
} else if (product.portable) {
155-
return path.join(path.dirname(this.appPath), product.portable, 'extensions');
143+
} else if (process.env['VSCODE_PORTABLE']) {
144+
return path.join(process.env['VSCODE_PORTABLE'], 'extensions');
156145
} else {
157146
return path.join(this.userHome, product.dataFolderName, 'extensions');
158147
}

src/vs/platform/node/product.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export interface IProductConfiguration {
7474
};
7575
logUploaderUrl: string;
7676
portable?: string;
77-
portableTemp?: string;
7877
}
7978

8079
export interface ISurveyData {

src/vs/workbench/parts/terminal/node/terminalProcess.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ function cleanEnv() {
116116
'PTYCOLS',
117117
'PTYROWS',
118118
'PTYSHELLCMDLINE',
119-
'VSCODE_LOGS'
119+
'VSCODE_LOGS',
120+
'VSCODE_PORTABLE'
120121
];
121122
keys.forEach(function (key) {
122123
if (process.env[key]) {

0 commit comments

Comments
 (0)