Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#242] No scan symlinks as md files #261

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good change 👍

And I would like it to be placed to a different commit 😸

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the addition below should probably belong to the main commit )

Also, I would add a description to that commit you extracted after all. At a first glance, it's not clear why exactly you delete this line, maybe it was meant to contain some important information and should be extended, not removed. If in the commit description you mention that this was an accidental copy-paste, that would make the reasoning much clearer for an arbitrary git history reader.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good, thank you 👍

* [#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