Skip to content

Explicitly use Posix's splitDirectories #47

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions src/CabalFmt/Fields/SourceFiles.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module CabalFmt.Fields.SourceFiles (
fileFields,
) where

import System.FilePath.Posix (splitDirectories)
-- Make sure we explicitly use Posix's splitDirectories
-- when parsing glob syntax since only `/` is valid, and not '\\'
import qualified System.FilePath.Posix as Posix (splitDirectories)

import qualified Distribution.FieldGrammar as C
import qualified Distribution.Fields as C
Expand Down Expand Up @@ -46,7 +48,7 @@ pretty :: [FilePath] -> PP.Doc
pretty
= PP.vcat . map C.showFilePath
. nub
. sortBy (cmp `on` map strToLower . splitDirectories)
. sortBy (cmp `on` map strToLower . Posix.splitDirectories)
where
cmp a b = case dropCommonPrefix a b of
([], []) -> EQ
Expand Down
8 changes: 5 additions & 3 deletions src/CabalFmt/Glob.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module CabalFmt.Glob where

import Data.List (isInfixOf)
import Data.List.NonEmpty (NonEmpty (..))
import System.FilePath.Posix (splitDirectories)
-- Make sure we explicitly use Posix's splitDirectories
-- when parsing glob syntax since only `/` is valid, and not '\\'
import qualified System.FilePath.Posix as Posix (splitDirectories)

import CabalFmt.Prelude

Expand All @@ -27,7 +29,7 @@ data GlobChar
-- [False,False,True,True]
--
match :: Glob -> FilePath -> Bool
match (Glob g1 gs0) fp = go0 (splitDirectories fp) where
match (Glob g1 gs0) fp = go0 (Posix.splitDirectories fp) where
go0 [] = False
go0 (p:ps) = if p == g1 then go ps gs0 else False

Expand All @@ -47,7 +49,7 @@ match (Glob g1 gs0) fp = go0 (splitDirectories fp) where
matches (x:xs) (GlobChar c : cs) = if x == c then matches xs cs else False

parseGlob :: String -> Either String Glob
parseGlob input = case splitDirectories input of
parseGlob input = case Posix.splitDirectories input of
[] -> Left "empty path"
(x:xs) -> do
p <- parseFirstPiece x
Expand Down