From bc151c191c90900038348f6de0e53f39d2f82e0a Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 25 Dec 2024 02:23:05 +0100 Subject: [PATCH] fix: return original error when can't rename overwrite --- src/index.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0bf7e3c..175cb7c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,7 +88,15 @@ async function forceSymlink ( warn = `Symlink wanted name was occupied by directory or file. Old entity removed: "${parentDir}${pathLib.sep}{${pathLib.basename(path)}".` } else { const ignore = `.ignored_${pathLib.basename(path)}` - await renameOverwrite(path, pathLib.join(parentDir, ignore)) + try { + await renameOverwrite(path, pathLib.join(parentDir, ignore)) + } catch (error) { + if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') { + throw initialErr + } + throw error + } + warn = `Symlink wanted name was occupied by directory or file. Old entity moved: "${parentDir}${pathLib.sep}{${pathLib.basename(path)} => ${ignore}".` } @@ -185,7 +193,14 @@ function forceSymlinkSync ( warn = `Symlink wanted name was occupied by directory or file. Old entity removed: "${parentDir}${pathLib.sep}{${pathLib.basename(path)}".` } else { const ignore = `.ignored_${pathLib.basename(path)}` - renameOverwrite.sync(path, pathLib.join(parentDir, ignore)) + try { + renameOverwrite.sync(path, pathLib.join(parentDir, ignore)) + } catch (error) { + if (util.types.isNativeError(error) && 'code' in error && error.code === 'ENOENT') { + throw initialErr + } + throw error + } warn = `Symlink wanted name was occupied by directory or file. Old entity moved: "${parentDir}${pathLib.sep}{${pathLib.basename(path)} => ${ignore}".` }