diff --git a/src/Xrefcheck/Scan.hs b/src/Xrefcheck/Scan.hs index f3928b78..2cdee8c1 100644 --- a/src/Xrefcheck/Scan.hs +++ b/src/Xrefcheck/Scan.hs @@ -264,7 +264,10 @@ scanRepo scanMode rw formatsSupport config root = do gatherFileStatuses = map (second fst) processFile :: CanonicalPath -> IO (FileStatus, [ScanError 'Parse]) - processFile canonicalFile = case mscanner canonicalFile of + processFile canonicalFile = + ifM (pathIsSymbolicLink canonicalFile) + (pure (NotScannable, [])) + case mscanner canonicalFile of Nothing -> pure (NotScannable, []) Just scanner -> scanner canonicalFile <&> _1 %~ Scanned diff --git a/src/Xrefcheck/System.hs b/src/Xrefcheck/System.hs index 89d496d8..999f46f4 100644 --- a/src/Xrefcheck/System.hs +++ b/src/Xrefcheck/System.hs @@ -14,6 +14,7 @@ module Xrefcheck.System , getPosixRelativeChild , getPosixRelativeOrAbsoluteChild , hasIndirectionThroughParent + , pathIsSymbolicLink , takeDirectory , takeExtension , ( String takeExtension (UnsafeCanonicalPath p) = FP.takeExtension p +-- | 'System.Directory.pathIsSymbolicLink' version for 'CanonicalPath'. +pathIsSymbolicLink :: CanonicalPath -> IO Bool +pathIsSymbolicLink (UnsafeCanonicalPath p) = Directory.pathIsSymbolicLink p + -- | Get the list of directories, canonicalized, between two given paths. getDirsBetweenRootAndFile :: CanonicalPath -> CanonicalPath -> [CanonicalPath] getDirsBetweenRootAndFile (UnsafeCanonicalPath rootPath) file = diff --git a/tests/golden/check-symlinks/check-symlinks.bats b/tests/golden/check-symlinks/check-symlinks.bats new file mode 100644 index 00000000..84c1211e --- /dev/null +++ b/tests/golden/check-symlinks/check-symlinks.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +# SPDX-FileCopyrightText: 2022 Serokell +# +# SPDX-License-Identifier: MPL-2.0 + +load '../helpers/bats-support/load' +load '../helpers/bats-assert/load' +load '../helpers/bats-file/load' +load '../helpers' + + +@test "Checking that symlinks are not processed" { + to_temp xrefcheck -v + + assert_diff expected.gold +} diff --git a/tests/golden/check-symlinks/dir/a b/tests/golden/check-symlinks/dir/a new file mode 100644 index 00000000..e69de29b diff --git a/tests/golden/check-symlinks/dir/b.md b/tests/golden/check-symlinks/dir/b.md new file mode 100644 index 00000000..f4ec6f87 --- /dev/null +++ b/tests/golden/check-symlinks/dir/b.md @@ -0,0 +1,11 @@ + + +[Empty file](a) + +[Symlink ref](../s.md) + +[Symlink ref with anchor](../s.md#a) diff --git a/tests/golden/check-symlinks/expected.gold b/tests/golden/check-symlinks/expected.gold new file mode 100644 index 00000000..f4b05c27 --- /dev/null +++ b/tests/golden/check-symlinks/expected.gold @@ -0,0 +1,20 @@ +=== Repository data === + + dir/b.md: + - references: + - reference (relative) at src:7:1-15: + - text: "Empty file" + - link: a + - anchor: - + - reference (relative) at src:9:1-22: + - text: "Symlink ref" + - link: ../s.md + - anchor: - + - reference (relative) at src:11:1-36: + - text: "Symlink ref with anchor" + - link: ../s.md + - anchor: a + - anchors: + none + +All repository links are valid. diff --git a/tests/golden/check-symlinks/s.md b/tests/golden/check-symlinks/s.md new file mode 120000 index 00000000..c92f149c --- /dev/null +++ b/tests/golden/check-symlinks/s.md @@ -0,0 +1 @@ +dir/b.md \ No newline at end of file