recursive: true is mkdir -p

This commit is contained in:
Manav Rathi 2024-03-22 15:31:45 +05:30
parent c41bb571f6
commit b6b4ee7e3a
No known key found for this signature in database
4 changed files with 9 additions and 22 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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}`);

View file

@ -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;
}