Преглед на файлове

recursive: true is mkdir -p

Manav Rathi преди 1 година
родител
ревизия
b6b4ee7e3a
променени са 4 файла, в които са добавени 9 реда и са изтрити 22 реда
  1. 1 3
      desktop/src/api/cache.ts
  2. 3 8
      desktop/src/preload.ts
  3. 1 4
      desktop/src/services/clipService.ts
  4. 4 7
      desktop/src/utils/temp.ts

+ 1 - 3
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);
 }
 

+ 3 - 8
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);
 }
 

+ 1 - 4
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}`);

+ 4 - 7
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;
 }