From dad3602d2b2587dd7016a9fe214b34b7d225f54e Mon Sep 17 00:00:00 2001 From: ddorando <87425418+ddorando@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:07:39 +0300 Subject: [PATCH] use fstatSync instead of statSync --- dist/index.js | 8 +++++--- src/utils.ts | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index ae4cb49..64739be 100644 --- a/dist/index.js +++ b/dist/index.js @@ -654,9 +654,7 @@ class GitAuthHelper { if (this.gitConfigPath.length === 0) { this.gitConfigPath = yield this.git.getGitPath('config'); } - console.log(this.gitConfigPath); let content = (yield fs.promises.readFile(this.gitConfigPath)).toString(); - console.log(content); const index = content.indexOf(find); if (index < 0 || index != content.lastIndexOf(find)) { throw new Error(`Unable to replace '${find}' in ${this.gitConfigPath}`); @@ -1413,9 +1411,10 @@ function fileExistsSync(path) { if (!path) { throw new Error("Arg 'path' must not be empty"); } + const fd = fs.openSync(path, 'r'); let stats; try { - stats = fs.statSync(path); + stats = fs.fstatSync(fd); } catch (error) { if (hasErrorCode(error) && error.code === 'ENOENT') { @@ -1423,6 +1422,9 @@ function fileExistsSync(path) { } throw new Error(`Encountered an error when checking whether path '${path}' exists: ${getErrorMessage(error)}`); } + finally { + fs.closeSync(fd); + } if (!stats.isDirectory()) { return true; } diff --git a/src/utils.ts b/src/utils.ts index 9188bee..275418b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -147,9 +147,10 @@ export function fileExistsSync(path: string): boolean { throw new Error("Arg 'path' must not be empty") } + const fd = fs.openSync(path, 'r') let stats: fs.Stats try { - stats = fs.statSync(path) + stats = fs.fstatSync(fd) } catch (error) { if (hasErrorCode(error) && error.code === 'ENOENT') { return false @@ -160,6 +161,8 @@ export function fileExistsSync(path: string): boolean { error )}` ) + } finally { + fs.closeSync(fd) } if (!stats.isDirectory()) {