Skip to content

Commit

Permalink
Merge pull request #261 from serokell/aeqz/#242-no-scan-symlinks-as-md
Browse files Browse the repository at this point in the history
[#242] No scan symlinks as md files
  • Loading branch information
aeqz authored Jan 19, 2023
2 parents 5d182c0 + fef5153 commit ea64357
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ Unreleased
* [#254](https://github.com/serokell/xrefcheck/pull/254)
+ Now the `dump-config` command does not overwrite a file unless explicitly told with a
`--force` flag. Also, a `--stdout` flag allows to print the config to stdout instead.
the configured Markdown flavour.
* [#250](https://github.com/serokell/xrefcheck/pull/250)
+ Now the redirect behavior for external references can be modified via rules in the
configuration file with the `externalRefRedirects` parameter.
* [#261](https://github.com/serokell/xrefcheck/pull/261)
+ Symlinks are now not processed by the scanner.

0.2.2
==========
Expand Down
5 changes: 4 additions & 1 deletion src/Xrefcheck/Scan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/Xrefcheck/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Xrefcheck.System
, getPosixRelativeChild
, getPosixRelativeOrAbsoluteChild
, hasIndirectionThroughParent
, pathIsSymbolicLink
, takeDirectory
, takeExtension
, (</)
Expand Down Expand Up @@ -94,6 +95,10 @@ takeDirectory (UnsafeCanonicalPath p) = UnsafeCanonicalPath $ FP.takeDirectory p
takeExtension :: CanonicalPath -> 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 =
Expand Down
17 changes: 17 additions & 0 deletions tests/golden/check-symlinks/check-symlinks.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bats

# SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io>
#
# 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
}
Empty file.
11 changes: 11 additions & 0 deletions tests/golden/check-symlinks/dir/b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
- SPDX-FileCopyrightText: 2023 Serokell <https://serokell.io>
-
- SPDX-License-Identifier: MPL-2.0
-->

[Empty file](a)

[Symlink ref](../s.md)

[Symlink ref with anchor](../s.md#a)
20 changes: 20 additions & 0 deletions tests/golden/check-symlinks/expected.gold
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions tests/golden/check-symlinks/s.md

0 comments on commit ea64357

Please sign in to comment.