mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
@@ -88,5 +88,5 @@ export function activate(
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
fs.rmSync(temp.getInstanceTempDir(), { recursive: true, force: true });
|
||||
fs.rmSync(temp.instanceTempDir.value, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { lazy } from './lazy';
|
||||
|
||||
function makeRandomHexString(length: number): string {
|
||||
const chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||
@@ -17,31 +18,17 @@ function makeRandomHexString(length: number): string {
|
||||
return result;
|
||||
}
|
||||
|
||||
const getRootTempDir = (() => {
|
||||
let dir: string | undefined;
|
||||
return () => {
|
||||
if (!dir) {
|
||||
const filename = `vscode-typescript${process.platform !== 'win32' && process.getuid ? process.getuid() : ''}`;
|
||||
dir = path.join(os.tmpdir(), filename);
|
||||
}
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
return dir;
|
||||
};
|
||||
})();
|
||||
const rootTempDir = lazy(() => {
|
||||
const filename = `vscode-typescript${process.platform !== 'win32' && process.getuid ? process.getuid() : ''}`;
|
||||
return path.join(os.tmpdir(), filename);
|
||||
});
|
||||
|
||||
export const getInstanceTempDir = (() => {
|
||||
let dir: string | undefined;
|
||||
return () => {
|
||||
dir ??= path.join(getRootTempDir(), makeRandomHexString(20));
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
return dir;
|
||||
};
|
||||
})();
|
||||
export const instanceTempDir = lazy(() => {
|
||||
const dir = path.join(rootTempDir.value, makeRandomHexString(20));
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
});
|
||||
|
||||
export function getTempFile(prefix: string): string {
|
||||
return path.join(getInstanceTempDir(), `${prefix}-${makeRandomHexString(20)}.tmp`);
|
||||
return path.join(instanceTempDir.value, `${prefix}-${makeRandomHexString(20)}.tmp`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user