Skip to content

Commit

Permalink
mkdirp edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
cloverich committed Dec 9, 2024
1 parent 2a9a035 commit 37cc19b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/electron/ensureDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require("fs");
* Borrowed from api files, since its typescript and this is not
* Reconcile that later
*/
exports.ensureDir = function ensureDir(directory) {
exports.ensureDir = function ensureDir(directory, create = true) {
if (!directory) {
throw new Error("ensureDir called with no directory path");
}
Expand Down
8 changes: 7 additions & 1 deletion src/preload/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ export class Files {
try {
await fs.promises.mkdir(dir, { recursive: true });
} catch (err) {
// If it already exists, good to go
// note: ts can't find this type: instanceof ErrnoException
if ((err as any).code === "EEXIST") {
// confirm it's a directory
const stats = await fs.promises.stat(dir);
if (!stats.isDirectory()) {
throw new Error(`[Files.mkdirp] ${dir} already exists as a file`);
}

// already exists, good to go
return dir;
} else {
throw err;
Expand Down

0 comments on commit 37cc19b

Please sign in to comment.