@@ -85,9 +85,10 @@ module Streamly.Internal.FileSystem.Path.Common
8585 , normalizeSeparators
8686 -- , normalize -- separators and /./ components (split/combine)
8787 , eqPathBytes
88- , EqCfg (.. )
89- , eqCfg
90- , eqPathWith
88+ , EqCfg
89+ , ignoreTrailingSeparators
90+ , ignoreCase
91+ , allowRelativeEquality
9192 , eqPath
9293 -- , commonPrefix -- common prefix of two paths
9394 -- , eqPrefix -- common prefix is equal to first path
@@ -1388,11 +1389,19 @@ eqPathBytes = Array.byteEq
13881389-- | Options for path comparison operation. By default path comparison uses a
13891390-- strict criteria for equality. The following options are provided to
13901391-- control the strictness.
1392+ --
1393+ -- The default configuration is as follows:
1394+ -- >>> :{
1395+ -- defaultMod = ignoreTrailingSeparators False
1396+ -- . ignoreCase False
1397+ -- . allowRelativeEquality False
1398+ -- :}
1399+ --
13911400data EqCfg =
13921401 EqCfg
1393- { ignoreTrailingSeparators :: Bool -- ^ Allows "x\/" == "x"
1394- , ignoreCase :: Bool -- ^ Allows "x" == \"X\"
1395- , allowRelativeEquality :: Bool
1402+ { _ignoreTrailingSeparators :: Bool -- ^ Allows "x\/" == "x"
1403+ , _ignoreCase :: Bool -- ^ Allows "x" == \"X\"
1404+ , _allowRelativeEquality :: Bool
13961405 -- ^ A leading dot is ignored, thus ".\/x" == ".\/x" and ".\/x" == "x".
13971406 -- On Windows allows "\/x" == \/x" and "C:x == C:x"
13981407
@@ -1413,11 +1422,21 @@ data EqCfg =
14131422--
14141423eqCfg :: EqCfg
14151424eqCfg = EqCfg
1416- { ignoreTrailingSeparators = False
1417- , ignoreCase = False
1418- , allowRelativeEquality = False
1425+ { _ignoreTrailingSeparators = False
1426+ , _ignoreCase = False
1427+ , _allowRelativeEquality = False
14191428 }
14201429
1430+ ignoreTrailingSeparators :: Bool -> EqCfg -> EqCfg
1431+ ignoreTrailingSeparators val conf = conf { _ignoreTrailingSeparators = val }
1432+
1433+ ignoreCase :: Bool -> EqCfg -> EqCfg
1434+ ignoreCase val conf = conf { _ignoreCase = val }
1435+
1436+ allowRelativeEquality :: Bool -> EqCfg -> EqCfg
1437+ allowRelativeEquality val conf = conf { _allowRelativeEquality = val }
1438+
1439+
14211440data PosixRoot = PosixRootAbs | PosixRootRel deriving Eq
14221441
14231442data WindowsRoot =
@@ -1521,38 +1540,34 @@ eqComponentsWith ignCase decoder os a b =
15211540 Array. byteEq (splitPath_ os a) (splitPath_ os b)
15221541
15231542-- XXX can we do something like SpecConstr for such functions e.g. without
1524- -- inlining the function we can use two copies one for allowRelativeEquality
1543+ -- inlining the function we can use two copies one for _allowRelativeEquality
15251544-- True and other for False and so on for other values of PathEq.
15261545
1527- {-# INLINE eqPathWith #-}
1528- eqPathWith :: (Unbox a , Integral a ) =>
1546+ {-# INLINE eqPath #-}
1547+ eqPath :: (Unbox a , Integral a ) =>
15291548 (Stream Identity a -> Stream Identity Char )
1530- -> OS -> EqCfg -> Array a -> Array a -> Bool
1531- eqPathWith decoder os EqCfg { .. } a b =
1549+ -> OS -> ( EqCfg -> EqCfg ) -> Array a -> Array a -> Bool
1550+ eqPath decoder os configMod a b =
15321551 let (rootA, stemA) = splitRoot os a
15331552 (rootB, stemB) = splitRoot os b
15341553
15351554 eqRelative =
1536- if allowRelativeEquality
1537- then eqRootLax ignoreCase os rootA rootB
1555+ if _allowRelativeEquality
1556+ then eqRootLax _ignoreCase os rootA rootB
15381557 else (not (isRootRelative os rootA)
15391558 && not (isRootRelative os rootB))
1540- && eqRootStrict ignoreCase os rootA rootB
1559+ && eqRootStrict _ignoreCase os rootA rootB
15411560
15421561 -- XXX If one ends in a "." and the other ends in ./ (and same for ".."
15431562 -- and "../") then they can be equal. We can append a slash in these two
15441563 -- cases before comparing.
15451564 eqTrailingSep =
1546- ignoreTrailingSeparators
1565+ _ignoreTrailingSeparators
15471566 || hasTrailingSeparator os a == hasTrailingSeparator os b
15481567
15491568 in
15501569 eqRelative
15511570 && eqTrailingSep
1552- && eqComponentsWith ignoreCase decoder os stemA stemB
1553-
1554- {-# INLINE eqPath #-}
1555- eqPath :: (Unbox a , Integral a ) =>
1556- (Stream Identity a -> Stream Identity Char )
1557- -> OS -> Array a -> Array a -> Bool
1558- eqPath decoder os = eqPathWith decoder os eqCfg
1571+ && eqComponentsWith _ignoreCase decoder os stemA stemB
1572+ where
1573+ EqCfg {.. } = configMod eqCfg
0 commit comments