diff --git a/libraries/deno-commons-mod.ts b/libraries/deno-commons-mod.ts index b74697c..e9a052f 100644 --- a/libraries/deno-commons-mod.ts +++ b/libraries/deno-commons-mod.ts @@ -909,9 +909,7 @@ export async function writeStringToFile( } } else { const parentDirname = dirname(newFilename); - if (!await existsPath(parentDirname)) { - await makeDirectory(parentDirname); - } + await makeDirectoryIfNotExists(parentDirname); if (isDeno()) { await Deno.writeTextFile(newFilename, data); } else { @@ -936,6 +934,15 @@ export async function removePath(path: string): Promise { } } +export async function makeDirectoryIfNotExists( + directory: string, + recursive?: boolean, +): Promise { + if (!await existsPath(directory)) { + await makeDirectory(directory, recursive); + } +} + export async function makeDirectory( directory: string, recursive?: boolean, @@ -1126,9 +1133,7 @@ export async function readWithLocalCache( cacheKeyHash.substring(0, 2), cacheKeyHash.substring(2, 4), ); - if (!await existsPath(cacheDir)) { - await makeDirectory(cacheDir, true); - } + await makeDirectoryIfNotExists(cacheDir, true); const cacheFile = joinPath(cacheDir, cacheKeyHash); log.debug(`key: ${cacheKey} --> ${cacheFile}`); const cachedContent = await readFileToString(cacheFile); @@ -1426,9 +1431,7 @@ export async function fetchFileWithCache( } } - if (!await existsPath(fileCacheDir)) { - await makeDirectory(fileCacheDir); - } + await makeDirectoryIfNotExists(fileCacheDir); try { const fetchResponse = await fetchDataWithTimeout(url, {