Skip to content

Commit

Permalink
Fix mkdir condition
Browse files Browse the repository at this point in the history
  • Loading branch information
shirish87 committed Feb 6, 2024
1 parent d1ffbe6 commit 81f45a1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/fs-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ export async function ensureDirExists(
// const { lstat, mkdir, chmod, constants } = await import("node:fs/promises");
dirFlags = dirFlags ?? constants.R_OK | constants.W_OK;
const dirPath = resolve(binHome);
const dirStat = await lstat(dirPath);
const dirStat = await lstat(dirPath).catch(() => null);

if (!dirStat.isDirectory()) {
if (!dirStat || !dirStat.isDirectory()) {
await mkdir(dirPath, { recursive: true, mode: dirMode });
}

if ((dirStat.mode & dirFlags) !== dirFlags) {
if (dirStat && (dirStat.mode & dirFlags) !== dirFlags) {
await chmod(dirPath, dirMode);
}

Expand Down

0 comments on commit 81f45a1

Please sign in to comment.