From 1b4ea8689094ecf2e3a9c8b6ff0284580320da87 Mon Sep 17 00:00:00 2001 From: Anton Sorokin Date: Tue, 11 Oct 2022 23:35:44 +0300 Subject: [PATCH] [#164] Use only '/' as path separator 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 --- src/Xrefcheck/Core.hs | 4 ++-- src/Xrefcheck/Scan.hs | 2 +- src/Xrefcheck/System.hs | 5 ++--- src/Xrefcheck/Util.hs | 2 +- src/Xrefcheck/Verify.hs | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Xrefcheck/Core.hs b/src/Xrefcheck/Core.hs index 265d04ef..933ac2bb 100644 --- a/src/Xrefcheck/Core.hs +++ b/src/Xrefcheck/Core.hs @@ -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) @@ -314,7 +314,7 @@ canonizeLocalRef :: Text -> Text canonizeLocalRef ref = maybe ref canonizeLocalRef (T.stripPrefix localPrefix ref) where - localPrefix = toText ['.', pathSeparator] + localPrefix = "./" ----------------------------------------------------------- -- Visualisation diff --git a/src/Xrefcheck/Scan.hs b/src/Xrefcheck/Scan.hs index a6afa75c..7156bfbb 100644 --- a/src/Xrefcheck/Scan.hs +++ b/src/Xrefcheck/Scan.hs @@ -36,7 +36,7 @@ import Data.Map qualified as M import Data.Reflection (Given) import Fmt (Buildable (..)) 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 diff --git a/src/Xrefcheck/System.hs b/src/Xrefcheck/System.hs index d3fbad71..37b9fd58 100644 --- a/src/Xrefcheck/System.hs +++ b/src/Xrefcheck/System.hs @@ -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) @@ -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} diff --git a/src/Xrefcheck/Util.hs b/src/Xrefcheck/Util.hs index 0b83771a..b7795392 100644 --- a/src/Xrefcheck/Util.hs +++ b/src/Xrefcheck/Util.hs @@ -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 diff --git a/src/Xrefcheck/Verify.hs b/src/Xrefcheck/Verify.hs index e7ebacd8..c7a20fc5 100644 --- a/src/Xrefcheck/Verify.hs +++ b/src/Xrefcheck/Verify.hs @@ -57,7 +57,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)