packages feed

path 0.5.10 → 0.5.11

raw patch · 3 files changed

+29/−3 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG view
@@ -1,4 +1,7 @@-0.5.10+0.5.11:+	* Add replaceExtension and fileExtension++0.5.10: 	* Disallow /. for absolute file 	* Disallow foo/. for relative file 
path.cabal view
@@ -1,5 +1,5 @@ name:                path-version:             0.5.10+version:             0.5.11 synopsis:            Support for well-typed paths description:         Support for well-typed paths. license:             BSD3
src/Path.hs view
@@ -41,6 +41,8 @@   ,parent   ,filename   ,dirname+  ,fileExtension+  ,setFileExtension   -- * Conversion   ,toFilePath   ,fromAbsDir@@ -54,6 +56,7 @@ import           Control.Monad.Catch (MonadThrow(..)) import           Data.Aeson (FromJSON (..)) import qualified Data.Aeson.Types as Aeson+import           Data.Coerce import           Data.Data import           Data.List import           Data.Maybe@@ -149,7 +152,8 @@   if not (FilePath.isAbsolute filepath) &&      not (hasParentDir filepath) &&      not (null filepath) &&-     filepath /= "." && (normalizeFilePath filepath) /= curDirNormalizedFP &&+     filepath /= "." &&+     normalizeFilePath filepath /= curDirNormalizedFP &&      filepath /= ".." &&      FilePath.isValid filepath      then return (Path (normalizeDir filepath))@@ -391,6 +395,25 @@ dirname :: Path b Dir -> Path Rel Dir dirname (Path l) =   Path (last (FilePath.splitPath l))++-- | Get extension from given file path.+--+-- @since 0.5.11+fileExtension :: Path b File -> String+fileExtension = FilePath.takeExtension . toFilePath++-- | Replace\/add extension to given file path. Throws if the+-- resulting filename does not parse.+--+-- @since 0.5.11+setFileExtension :: MonadThrow m+  => String            -- ^ Extension to set+  -> Path b File       -- ^ Old file name+  -> m (Path b File)   -- ^ New file name with the desired extension+setFileExtension ext (Path path) =+  if FilePath.isAbsolute path+    then fmap coerce (parseAbsFile (FilePath.replaceExtension path ext))+    else fmap coerce (parseRelFile (FilePath.replaceExtension path ext))  -------------------------------------------------------------------------------- -- Internal functions