Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 9 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@
"semver": "^7.5.2",
"stack-trace": "0.0.10",
"sudo-prompt": "^9.2.1",
"tmp": "^0.0.33",
"tmp": "^0.2.5",
"uint64be": "^3.0.0",
"unicode": "^14.0.0",
"vscode-debugprotocol": "^1.28.0",
Expand Down
24 changes: 8 additions & 16 deletions src/client/common/platform/fs-temp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ import * as tmp from 'tmp';
import { ITempFileSystem, TemporaryFile } from './types';

interface IRawTempFS {
// TODO (https://github.com/microsoft/vscode/issues/84517)
// This functionality has been requested for the
// VS Code FS API (vscode.workspace.fs.*).
file(
config: tmp.Options,

callback?: (err: any, path: string, fd: number, cleanupCallback: () => void) => void,
): void;
fileSync(config?: tmp.Options): tmp.SynchrounousResult;
}

// Operations related to temporary files and directories.
Expand All @@ -35,14 +28,13 @@ export class TemporaryFileSystem implements ITempFileSystem {
mode,
};
return new Promise<TemporaryFile>((resolve, reject) => {
this.raw.file(opts, (err, filename, _fd, cleanUp) => {
if (err) {
return reject(err);
}
resolve({
filePath: filename,
dispose: cleanUp,
});
const { name, removeCallback } = this.raw.fileSync(opts);
if (!name) {
return reject(new Error('Failed to create temp file'));
}
resolve({
filePath: name,
dispose: removeCallback,
});
});
}
Expand Down
17 changes: 10 additions & 7 deletions src/test/common/platform/fs-temp.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import { TemporaryFileSystem } from '../../../client/common/platform/fs-temp';

interface IDeps {
// tmp module
file(
config: { postfix?: string; mode?: number },

callback?: (err: any, path: string, fd: number, cleanupCallback: () => void) => void,
): void;
fileSync(config: {
postfix?: string;
mode?: number;
}): {
name: string;
fd: number;
removeCallback(): void;
};
}

suite('FileSystem - temp files', () => {
Expand All @@ -28,7 +31,7 @@ suite('FileSystem - temp files', () => {
suite('createFile', () => {
test(`fails if the raw call fails`, async () => {
const failure = new Error('oops');
deps.setup((d) => d.file({ postfix: '.tmp', mode: undefined }, TypeMoq.It.isAny()))
deps.setup((d) => d.fileSync({ postfix: '.tmp', mode: undefined }))
// fail with an arbitrary error
.throws(failure);

Expand All @@ -40,7 +43,7 @@ suite('FileSystem - temp files', () => {

test(`fails if the raw call "returns" an error`, async () => {
const failure = new Error('oops');
deps.setup((d) => d.file({ postfix: '.tmp', mode: undefined }, TypeMoq.It.isAny())).callback((_cfg, cb) =>
deps.setup((d) => d.fileSync({ postfix: '.tmp', mode: undefined })).callback((_cfg, cb) =>
cb(failure, '...', -1, () => {}),
);

Expand Down
Loading