Skip to content

Commit

Permalink
Fixes file check failing with folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
GasparAdragna committed Sep 7, 2024
1 parent 61758e0 commit ba2c27e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit ba2c27e

Please sign in to comment.