From d719ffe35b1b20b9a9fd5e8f92b9d49921471344 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Wed, 29 Jan 2020 09:25:00 -0800 Subject: [PATCH] Clean fs resources in the background --- src/client/common/platform/fileSystem.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/common/platform/fileSystem.ts b/src/client/common/platform/fileSystem.ts index 5959a3234ced..dbde159cfc7c 100644 --- a/src/client/common/platform/fileSystem.ts +++ b/src/client/common/platform/fileSystem.ts @@ -8,6 +8,7 @@ import * as glob from 'glob'; import { injectable } from 'inversify'; import { promisify } from 'util'; import * as vscode from 'vscode'; +import '../../common/extensions'; import { createDeferred } from '../utils/async'; import { isFileNotFoundError, isNoPermissionsError } from './errors'; import { FileSystemPaths, FileSystemPathUtils } from './fs-paths'; @@ -460,14 +461,16 @@ export class FileSystem implements IFileSystem { let fd: number; try { fd = await fs.open(filePath, flags); + // Clean resources in the background. + fs.close(fd) + .finally(() => fs.unlink(filePath)) + .ignoreErrors(); } catch (err) { if (isNoPermissionsError(err)) { return true; } throw err; // re-throw } - await fs.close(fd); - await fs.unlink(filePath); return false; } }