Skip to content

Commit

Permalink
[#164] Use only '/' as path separator
Browse files Browse the repository at this point in the history
Problem: in markdown links, '/' should always be used as path separator ,
e.g. GitHub renderer is not threating link `[x](a\b.md)` as a link
to file in dir `a`
We use OS-dependent file separators everywhere, so
e.g. `canonizeLocalRef "./a.md"="./a.md`"` on Windows

Solution: replace '\' to '/' while constructing repo tree if needed
and then use only '/', preferring functions from `System.FilePath.Posix`.
We can do this, since 'a/b' and `a\b` are equivalent paths on Windows
  • Loading branch information
Sorokin-Anton committed Nov 29, 2022
1 parent 09783e0 commit aba295b
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Xrefcheck/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Data.List qualified as L
import Data.Reflection (Given)
import Data.Text qualified as T
import Fmt (Buildable (..))
import System.FilePath (isPathSeparator, pathSeparator)
import System.FilePath.Posix (isPathSeparator)
import Text.Interpolation.Nyan
import Time (Second, Time)

Expand Down Expand Up @@ -339,7 +339,7 @@ canonizeLocalRef :: Text -> Text
canonizeLocalRef ref =
maybe ref canonizeLocalRef (T.stripPrefix localPrefix ref)
where
localPrefix = toText ['.', pathSeparator]
localPrefix = "./"

-----------------------------------------------------------
-- Visualisation
Expand Down
2 changes: 1 addition & 1 deletion src/Xrefcheck/Scan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Data.Map qualified as M
import Data.Reflection (Given)
import Fmt (Buildable (..), fmt)
import System.Directory (doesDirectoryExist)
import System.FilePath
import System.FilePath.Posix
(dropTrailingPathSeparator, equalFilePath, splitDirectories, takeDirectory, takeExtension, (</>))
import System.Process (cwd, readCreateProcess, shell)
import Text.Interpolation.Nyan
Expand Down
5 changes: 2 additions & 3 deletions src/Xrefcheck/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import Data.Coerce (coerce)
import GHC.IO.Unsafe (unsafePerformIO)
import System.Directory (canonicalizePath)
import System.Environment (lookupEnv)
import System.FilePath (isRelative, (</>))
import System.FilePath.Glob (CompOptions (errorRecovery))
import System.FilePath.Glob qualified as Glob
import Text.Interpolation.Nyan
import System.FilePath.Posix (isRelative, (</>))

import Xrefcheck.Util (normaliseWithNoTrailing)

Expand Down Expand Up @@ -89,4 +88,4 @@ instance FromJSON RelGlobPattern where

-- | Glob compilation options we use.
globCompileOptions :: Glob.CompOptions
globCompileOptions = Glob.compDefault{errorRecovery = False}
globCompileOptions = Glob.compDefault{Glob.errorRecovery = False}
2 changes: 1 addition & 1 deletion src/Xrefcheck/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Data.Time (UTCTime)
import Data.Time.Clock (nominalDiffTimeToSeconds)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Fmt (Builder)
import System.FilePath (dropTrailingPathSeparator, normalise)
import System.FilePath.Posix (dropTrailingPathSeparator, normalise)
import Time (Second, Time (..), sec)

import Xrefcheck.Util.Colorize
Expand Down
2 changes: 1 addition & 1 deletion src/Xrefcheck/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Network.HTTP.Req
HttpMethod, NoReqBody (..), defaultHttpConfig, ignoreResponse, req, runReq, useURI)
import Network.HTTP.Types.Header (hRetryAfter)
import Network.HTTP.Types.Status (Status, statusCode, statusMessage)
import System.FilePath
import System.FilePath.Posix
(equalFilePath, joinPath, makeRelative, normalise, splitDirectories, takeDirectory, (</>))
import Text.Interpolation.Nyan
import Text.ParserCombinators.ReadPrec qualified as ReadPrec (lift)
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extra-deps:
- firefly-0.2.1.0@sha256:e9d73486464c3e223ec457e02b30ddd5b550fdbf6292b268c64581e2b07d888b,1519
- cmark-gfm-0.2.5
- git: https://github.com/serokell/nyan-interpolation
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
subdirs:
- full
- core
10 changes: 5 additions & 5 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ packages:
original:
hackage: cmark-gfm-0.2.5
- completed:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
name: nyan-interpolation
pantry-tree:
Expand All @@ -28,20 +28,20 @@ packages:
subdir: full
version: '0.9'
original:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
subdir: full
- completed:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
name: nyan-interpolation-core
pantry-tree:
sha256: 59d1c732629b06d0035229dccce484d6b4c3078d6bb3e493317afddc9be233df
sha256: 4802161ce5d38f895e3b5106c789bfbe20b8d12c2f6c5fcba3999bec105283bc
size: 1516
subdir: core
version: '0.9'
original:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
subdir: core
snapshots:
Expand Down

0 comments on commit aba295b

Please sign in to comment.