From b6b4ee7e3af696138f486a1135b2b12e37c4beee Mon Sep 17 00:00:00 2001
From: Manav Rathi <manav@mrmr.io>
Date: Fri, 22 Mar 2024 15:31:45 +0530
Subject: [PATCH] recursive: true is mkdir -p

---
 desktop/src/api/cache.ts            |  4 +---
 desktop/src/preload.ts              | 11 +++--------
 desktop/src/services/clipService.ts |  5 +----
 desktop/src/utils/temp.ts           | 11 ++++-------
 4 files changed, 9 insertions(+), 22 deletions(-)

diff --git a/desktop/src/api/cache.ts b/desktop/src/api/cache.ts
index c1a0b9871..fe5f7bd93 100644
--- a/desktop/src/api/cache.ts
+++ b/desktop/src/api/cache.ts
@@ -22,9 +22,7 @@ export async function openDiskCache(
     cacheLimitInBytes?: number,
 ) {
     const cacheBucketDir = await getCacheBucketDir(cacheName);
-    if (!existsSync(cacheBucketDir)) {
-        await fs.mkdir(cacheBucketDir, { recursive: true });
-    }
+    await fs.mkdir(cacheBucketDir, { recursive: true });
     return new DiskCache(cacheBucketDir, cacheLimitInBytes);
 }
 
diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts
index b66409137..8c717e8ab 100644
--- a/desktop/src/preload.ts
+++ b/desktop/src/preload.ts
@@ -143,11 +143,8 @@ const writeNodeStream = async (
 
 const exists = (path: string) => existsSync(path);
 
-const checkExistsAndCreateDir = async (dirPath: string) => {
-    if (!existsSync(dirPath)) {
-        await fs.mkdir(dirPath);
-    }
-};
+const checkExistsAndCreateDir = (dirPath: string) =>
+    fs.mkdir(dirPath, { recursive: true });
 
 const saveStreamToDisk = writeStream;
 
@@ -175,9 +172,7 @@ async function moveFile(
     }
     // check if destination folder exists
     const destinationFolder = path.dirname(destinationPath);
-    if (!existsSync(destinationFolder)) {
-        await fs.mkdir(destinationFolder, { recursive: true });
-    }
+    await fs.mkdir(destinationFolder, { recursive: true });
     await fs.rename(sourcePath, destinationPath);
 }
 
diff --git a/desktop/src/services/clipService.ts b/desktop/src/services/clipService.ts
index 145f00a4d..65b4a52bb 100644
--- a/desktop/src/services/clipService.ts
+++ b/desktop/src/services/clipService.ts
@@ -79,10 +79,7 @@ function getModelSavePath(modelName: string) {
 async function downloadModel(saveLocation: string, url: string) {
     // confirm that the save location exists
     const saveDir = path.dirname(saveLocation);
-    if (!existsSync(saveDir)) {
-        log.info("creating model save dir");
-        await fs.mkdir(saveDir, { recursive: true });
-    }
+    await fs.mkdir(saveDir, { recursive: true });
     log.info("downloading clip model");
     const res = await net.fetch(url);
     if (!res.ok) throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`);
diff --git a/desktop/src/utils/temp.ts b/desktop/src/utils/temp.ts
index 91496ce13..7bb20468a 100644
--- a/desktop/src/utils/temp.ts
+++ b/desktop/src/utils/temp.ts
@@ -1,17 +1,14 @@
 import { app } from "electron";
+import { existsSync } from "node:fs";
+import * as fs from "node:fs/promises";
 import path from "path";
-import { existsSync, mkdir } from "promise-fs";
-
-const ENTE_TEMP_DIRECTORY = "ente";
 
 const CHARACTERS =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
 export async function getTempDirPath() {
-    const tempDirPath = path.join(app.getPath("temp"), ENTE_TEMP_DIRECTORY);
-    if (!existsSync(tempDirPath)) {
-        await mkdir(tempDirPath);
-    }
+    const tempDirPath = path.join(app.getPath("temp"), "ente");
+    await fs.mkdir(tempDirPath, { recursive: true });
     return tempDirPath;
 }