From 101c447c71e09f1a40b3e09b12ea5a9edd639a19 Mon Sep 17 00:00:00 2001 From: dqunbp Date: Wed, 27 Nov 2024 14:48:41 +0400 Subject: [PATCH 1/2] Enhance cachePurgeMosaic to remove mosaic256 as well --- src/cache.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cache.mjs b/src/cache.mjs index e0b3637..33adefc 100644 --- a/src/cache.mjs +++ b/src/cache.mjs @@ -37,8 +37,9 @@ async function cacheInit() { } } -function cachePurgeMosaic() { - return fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic__`); +async function cachePurgeMosaic() { + await fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic__`, { recursive: true }); + await fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic256__`, { recursive: true }); } function mosaicTilesIterable() { From 53c9a54689572f865e7aaf118876b0853aea536b Mon Sep 17 00:00:00 2001 From: dqunbp Date: Wed, 27 Nov 2024 15:14:41 +0400 Subject: [PATCH 2/2] Update src/cache.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/cache.mjs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cache.mjs b/src/cache.mjs index 33adefc..4a913c6 100644 --- a/src/cache.mjs +++ b/src/cache.mjs @@ -38,8 +38,20 @@ async function cacheInit() { } async function cachePurgeMosaic() { - await fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic__`, { recursive: true }); - await fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic256__`, { recursive: true }); + try { + await Promise.all([ + fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic__`, { recursive: true }), + fs.promises.rmdir(`${TILES_CACHE_DIR_PATH}/__mosaic256__`, { recursive: true }) + ]); + // Recreate directories to maintain consistency with cacheInit + await Promise.all([ + fs.promises.mkdir(`${TILES_CACHE_DIR_PATH}/__mosaic__`, { recursive: true }), + fs.promises.mkdir(`${TILES_CACHE_DIR_PATH}/__mosaic256__`, { recursive: true }) + ]); + } catch (error) { + throw new Error(`Failed to purge mosaic cache: ${error.message}`); + } +} } function mosaicTilesIterable() {