From 0476db8ebc60807eb97c6fb5fe031e0b4f55714d Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Sat, 21 Nov 2015 16:12:12 +0600 Subject: [PATCH 1/4] =?UTF-8?q?Add=20=E2=80=98.stack-work=E2=80=99=20to=20?= =?UTF-8?q?=E2=80=98.gitignore=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 212b0d3..45bdf12 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ cabal-dev/ TAGS tags *.tag +.stack-work/ From 339f7587a346d7b3b3c6defcbbe64d8c24655f57 Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Sat, 21 Nov 2015 16:13:52 +0600 Subject: [PATCH 2/4] Remove unused language pragmas --- src/Path/Internal.hs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Path/Internal.hs b/src/Path/Internal.hs index 78a9cda..ce3792f 100644 --- a/src/Path/Internal.hs +++ b/src/Path/Internal.hs @@ -1,6 +1,4 @@ -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -- | Internal types and functions. From 733fa04ac31e4c94f468a5a5cdab79725367b52e Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Sat, 21 Nov 2015 16:14:54 +0600 Subject: [PATCH 3/4] =?UTF-8?q?Write=20=E2=80=98isPrefixOf=E2=80=99=20and?= =?UTF-8?q?=20friends=20in=20infix=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Path.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Path.hs b/src/Path.hs index 2cdf467..9a7b76c 100644 --- a/src/Path.hs +++ b/src/Path.hs @@ -81,7 +81,7 @@ parseAbsDir :: MonadThrow m parseAbsDir filepath = if FilePath.isAbsolute filepath && not (null (normalizeDir filepath)) && - not (isPrefixOf "~/" filepath) && + not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) then return (Path (normalizeDir filepath)) else throwM (InvalidAbsDir filepath) @@ -96,7 +96,7 @@ parseRelDir :: MonadThrow m parseRelDir filepath = if not (FilePath.isAbsolute filepath) && not (null filepath) && - not (isPrefixOf "~/" filepath) && + not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) && not (null (normalizeDir filepath)) && filepath /= ".." @@ -112,7 +112,7 @@ parseAbsFile :: MonadThrow m parseAbsFile filepath = if FilePath.isAbsolute filepath && not (FilePath.hasTrailingPathSeparator filepath) && - not (isPrefixOf "~/" filepath) && + not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) && not (null (normalizeFile filepath)) && filepath /= ".." @@ -129,7 +129,7 @@ parseRelFile filepath = if not (FilePath.isAbsolute filepath || FilePath.hasTrailingPathSeparator filepath) && not (null filepath) && - not (isPrefixOf "~/" filepath) && + not ("~/" `isPrefixOf` filepath) && not (hasParentDir filepath) && not (null (normalizeFile filepath)) && filepath /= ".." @@ -140,9 +140,9 @@ parseRelFile filepath = -- This handles the logic of checking for different path separators on Windows. hasParentDir :: FilePath -> Bool hasParentDir filepath' = - (isSuffixOf "/.." filepath) || - (isInfixOf "/../" filepath) || - (isPrefixOf "../" filepath) + ("/.." `isSuffixOf` filepath) || + ("/../" `isInfixOf` filepath) || + ("../" `isPrefixOf` filepath) where filepath = case FilePath.pathSeparator of From 00fabad1f4aab2778f500372c86e0b295c3d1c54 Mon Sep 17 00:00:00 2001 From: mrkkrp Date: Sat, 21 Nov 2015 16:15:34 +0600 Subject: [PATCH 4/4] =?UTF-8?q?Add=20type-safe=20synonyms=20of=20=E2=80=98?= =?UTF-8?q?toFilePath=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps to “double check” programmers' assumptions about what kind of path he is converting into ‘FilePath’. Without these synonyms it's possible to silently convert wrong type of path into ‘FilePath’. --- src/Path.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Path.hs b/src/Path.hs index 9a7b76c..191e915 100644 --- a/src/Path.hs +++ b/src/Path.hs @@ -31,6 +31,10 @@ module Path ,dirname -- * Conversion ,toFilePath + ,fromAbsDir + ,fromRelDir + ,fromAbsFile + ,fromRelFile ) where @@ -203,6 +207,22 @@ mkRelFile s = toFilePath :: Path b t -> FilePath toFilePath (Path l) = l +-- | Convert absolute path to directory to 'FilePath' type. +fromAbsDir :: Path Abs Dir -> FilePath +fromAbsDir = toFilePath + +-- | Convert relative path to directory to 'FilePath' type. +fromRelDir :: Path Rel Dir -> FilePath +fromRelDir = toFilePath + +-- | Convert absolute path to file to 'FilePath' type. +fromAbsFile :: Path Abs File -> FilePath +fromAbsFile = toFilePath + +-- | Convert relative path to file to 'FilePath' type. +fromRelFile :: Path Rel File -> FilePath +fromRelFile = toFilePath + -------------------------------------------------------------------------------- -- Operations