From 4251665d7551e979e6b044d9349f8005a568bbb0 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 | 6 +++--- src/Xrefcheck/Util.hs | 2 +- src/Xrefcheck/Verify.hs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Xrefcheck/Core.hs b/src/Xrefcheck/Core.hs index 3c618285..99504214 100644 --- a/src/Xrefcheck/Core.hs +++ b/src/Xrefcheck/Core.hs @@ -21,7 +21,7 @@ import Data.Map qualified as M import Data.Reflection (Given) import Data.Text qualified as T import Fmt (Buildable (..), blockListF, blockListF', nameF, (+|), (|+)) -import System.FilePath (isPathSeparator, pathSeparator) +import System.FilePath.Posix (isPathSeparator) import Time (Second, Time) import Data.DList (DList) @@ -309,7 +309,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 f223a05f..50525859 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 (..), nameF, (+|), (|+)) import System.Directory (doesDirectoryExist) -import System.FilePath +import System.FilePath.Posix (dropTrailingPathSeparator, equalFilePath, splitDirectories, takeDirectory, takeExtension, ()) import System.Process (cwd, readCreateProcess, shell) import Text.Regex.TDFA.Common (CompOption (..), ExecOption (..), Regex) diff --git a/src/Xrefcheck/System.hs b/src/Xrefcheck/System.hs index 29dbc235..2b07825f 100644 --- a/src/Xrefcheck/System.hs +++ b/src/Xrefcheck/System.hs @@ -21,9 +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 System.FilePath.Posix (isRelative, ()) + import Xrefcheck.Util (normaliseWithNoTrailing) -- | We can quite safely treat surrounding filesystem as frozen, @@ -86,4 +86,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 19811d85..6536153d 100644 --- a/src/Xrefcheck/Util.hs +++ b/src/Xrefcheck/Util.hs @@ -26,7 +26,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 a322b62b..d61a51ea 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.ParserCombinators.ReadPrec qualified as ReadPrec (lift) import Text.Regex.TDFA.Text (Regex, regexec)