From ba2c27e0a367a8d369452d554661f1fd236dd75c Mon Sep 17 00:00:00 2001 From: GasparAdragna Date: Fri, 6 Sep 2024 21:29:51 -0300 Subject: [PATCH] Fixes file check failing with folder name --- lib/utils.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index fb5f2c3..6c6a5a8 100755 --- a/lib/utils.js +++ b/lib/utils.js @@ -122,6 +122,10 @@ function extractTrailingNumber (fileName) { return match ? +match[1] : null } +function extractFileName (fileName) { + return fileName.split(/(\\|\/)/g).pop() +} + async function isMatchingTime (filePath, time) { const { birthtimeMs } = await stat(filePath) return birthtimeMs >= time @@ -139,7 +143,7 @@ async function checkSymlink (fileName, linkPath) { const stats = await lstat(linkPath).then(stats => stats, () => null) if (stats?.isSymbolicLink()) { const existingTarget = await readlink(linkPath) - if (existingTarget === fileName) { + if (extractFileName(existingTarget) === extractFileName(fileName)) { return false } await unlink(linkPath) @@ -148,11 +152,10 @@ async function checkSymlink (fileName, linkPath) { } async function createSymlink (fileVal) { - const fileName = getFileName(fileVal) - const linkPath = join(dirname(fileName), 'current.log') - const shouldCreateSymlink = await checkSymlink(fileName, linkPath) + const linkPath = join(dirname(fileVal), 'current.log') + const shouldCreateSymlink = await checkSymlink(fileVal, linkPath) if (shouldCreateSymlink) { - await symlink(fileName.split(/(\\|\/)/g).pop(), linkPath) + await symlink(extractFileName(fileVal), linkPath) } }