system-canonicalpath 0.2.0.0 → 0.2.3.0
raw patch · 5 files changed
+111/−11 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Filesystem.CanonicalPath: canonicalPath' :: MonadIO m => Text -> m CanonicalPath
+ Filesystem.CanonicalPath: canonicalPathE' :: MonadIO m => Text -> m (Either Text CanonicalPath)
+ Filesystem.CanonicalPath: canonicalPathM' :: MonadIO m => Text -> m (Maybe CanonicalPath)
+ Filesystem.CanonicalPath: cpathToText :: CanonicalPath -> Text
+ Filesystem.CanonicalPath.Directory: copyFile_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()
+ Filesystem.CanonicalPath.Directory: createDirectoryIfMissing_ :: MonadIO m => Bool -> CanonicalPath -> UnsafePath -> m ()
+ Filesystem.CanonicalPath.Directory: createDirectory_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()
+ Filesystem.CanonicalPath.Directory: getDirectoryContents'' :: MonadIO m => CanonicalPath -> m [Text]
+ Filesystem.CanonicalPath.Directory: renameDirectory_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()
+ Filesystem.CanonicalPath.Directory: renameFile_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()
Files
- Filesystem/CanonicalPath.hs +5/−1
- Filesystem/CanonicalPath/Directory.hs +45/−0
- Filesystem/CanonicalPath/Internal.hs +39/−1
- changelog.md +20/−7
- system-canonicalpath.cabal +2/−2
Filesystem/CanonicalPath.hs view
@@ -23,8 +23,11 @@ -- * Constructors ,canonicalPath+ ,canonicalPath' ,canonicalPathM+ ,canonicalPathM' ,canonicalPathE+ ,canonicalPathE' ,unsafePath -- * Some IO functions@@ -35,7 +38,8 @@ -- * Conversion functions ,pathToText- ,textToPath) where+ ,textToPath+ ,cpathToText) where import Filesystem.CanonicalPath.Internal import Prelude ()
Filesystem/CanonicalPath/Directory.hs view
@@ -8,6 +8,8 @@ Redefinition of some functions from @System.Directory@ module. Some of them have different signature, because they need to work with @'CanonicalPath'@. For example, we can't create functions @createDirectory :: 'CanonicalPath' -> IO ()@, because it has no sense. How can we create directory that already exists? Instead we have function @createDirectory :: 'CanonicalPath' -> 'UnsafePath' -> IO 'CanonicalPath'@, that creates new directory in base existing directory with provided name. And also it returns @'CanonicalPath'@ of newly created directory. Isn't it nice? +A lot of functions come in two variants: one that returns resulting @'CanonicalPath' and second that ignores result (they end with '_' symbol).+ Happy Haskell Hacking! -} {-# LANGUAGE OverloadedStrings #-}@@ -39,6 +41,14 @@ where path = unsafePath cp </> dir {-|+Variant of @'createDirectory' that ignores resulting @'CanonicalPath'.++/Since 0.2.2.0/+-}+createDirectory_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()+createDirectory_ cp dir = voidM $ createDirectory cp dir++{-| @'createDirectoryIfMissing' parents dir@ creates a new directory @dir@ in @base@ directory. If the first argument is 'True' the function will also create all parent directories if they are missing. Function returns @'CanonicalPath'@ of created directory. For more information look for documentation of @'System.Directory.createDirectoryIfMissing'@.@@ -56,6 +66,14 @@ where path = unsafePath cp </> dir {-|+Variant of @'createDirectoryIfMissing' that ignores resulting @'CanonicalPath'.++/Since 0.2.2.0/+-}+createDirectoryIfMissing_ :: MonadIO m => Bool -> CanonicalPath -> UnsafePath -> m ()+createDirectoryIfMissing_ flag cp dir = voidM $ createDirectoryIfMissing flag cp dir++{-| @'removeDirectory' dir@ removes an existing directory /dir/. For more information look for documentation of @'System.Directory.removeDirectory'@.@@ -92,6 +110,14 @@ return . CanonicalPath $ unsafePath newPath </> dirname (addSlash p) {-|+Variant of @'renameDirectory' that ignores resulting @'CanonicalPath'.++/Since 0.2.2.0/+-}+renameDirectory_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()+renameDirectory_ cp p = voidM $ renameDirectory cp p++{-| @'getDirectoryContents' dir@ returns a list of /all/ entries in /dir/. If you want to have list of @'CanonicalPath'@ instead use function @'getDirectoryContents''@. For more information look for documentation of @'System.Directory.getDirectoryContents'@.@@ -110,6 +136,14 @@ getDirectoryContents' cp = liftIO . liftM (CanonicalPath . (</> ) up <$>) $ getDirectoryContents cp where up = unsafePath cp +{-|+The same as @'getDirectoryContents'@, but returns list of @'Text'@ instead of @'UnsafePath'@.++/Since 0.2.2.0/+-}+getDirectoryContents'' :: MonadIO m => CanonicalPath -> m [Text]+getDirectoryContents'' cp = liftIO . liftM (fromString <$>) $ preludeMap Directory.getDirectoryContents cp+ {- |If the operating system has a notion of current directories, 'getCurrentDirectory' returns an @'CanonicalPath'@ to the current directory of the calling process. For more information look for documentation of @'System.Directory.getCurrentDirectory'@.@@ -196,6 +230,14 @@ return . CanonicalPath $ unsafePath newPath </> filename p {-|+Variant of @'renameFile' that ignores resulting @'CanonicalPath'.++/Since 0.2.2.0/+-}+renameFile_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()+renameFile_ cp p = voidM $ renameFile cp p++{-| @'copyFile' old new@ copies the existing file from /old/ to /new/. If the /new/ file already exists, it is atomically replaced by the /old/ file. Neither path may refer to an existing directory. The permissions of /old/ are copied to /new/, if possible. For more information look for documentation of @'System.Directory.copyFile'@.@@ -210,3 +252,6 @@ do newPath <- canonicalPath $ parent newFile liftIO $ Directory.copyFile (toPrelude . unsafePath $ oldFile) (toPrelude newFile) return . CanonicalPath $ unsafePath newPath </> filename newFile++copyFile_ :: MonadIO m => CanonicalPath -> UnsafePath -> m ()+copyFile_ oldFile newFile = voidM $ copyFile oldFile newFile
Filesystem/CanonicalPath/Internal.hs view
@@ -2,8 +2,11 @@ module Filesystem.CanonicalPath.Internal (CanonicalPath(..) ,canonicalPath+ ,canonicalPath' ,canonicalPathM+ ,canonicalPathM' ,canonicalPathE+ ,canonicalPathE' ,unsafePath ,UnsafePath ,SafePath@@ -14,9 +17,11 @@ ,preludeMap ,pathToText ,textToPath+ ,cpathToText ,toPrelude ,fromPrelude- ,addSlash) where+ ,addSlash+ ,voidM) where import BasicPrelude import Control.Applicative as Applicative@@ -57,6 +62,14 @@ canonicalPath path = canonicalize path >>= either (error . textToString) (return . CanonicalPath) {-|+Version of @canonicalPath@ that takes @Text@ instead of @UnsafePath@.++/Since 0.2.1.0/+-}+canonicalPath' :: MonadIO m => Text -> m CanonicalPath+canonicalPath' = canonicalPath . textToPath++{-| Constructs @Maybe CanonicalPath@. >>> canonicalPathM "~"@@ -71,6 +84,14 @@ canonicalPathM path = canonicalize path >>= either (\_ -> return Nothing) (return . Just . CanonicalPath) {-|+Version of @canonicalPathM@ that takes @Text@ instead of @UnsafePath@.++/Since 0.2.1.0/+-}+canonicalPathM' :: MonadIO m => Text -> m (Maybe CanonicalPath)+canonicalPathM' = canonicalPathM . textToPath++{-| Constructs @Either Text CanonicalPath@. >>> canonicalPathE "~/"@@ -84,6 +105,14 @@ canonicalPathE :: MonadIO m => UnsafePath -> m (Either Text CanonicalPath) canonicalPathE path = canonicalize path >>= either (return . Left) (return . Right . CanonicalPath) +{-|+Version of @canonicalPathE@ that takes @Text@ instead of @UnsafePath@.++/Since 0.2.1.0/+-}+canonicalPathE' :: MonadIO m => Text -> m (Either Text CanonicalPath)+canonicalPathE' = canonicalPathE . textToPath+ -- | Convert @CanonicalPath@ to @Filesystem.FilePath@. -- -- /Since 0.1.0.0/@@ -221,6 +250,12 @@ textToPath :: Text -> UnsafePath textToPath = FilePath.fromText +-- | @'cpathToText' path@ converts 'CanonicalPath' to 'Text'.+--+-- /Since 0.2.3.0/+cpathToText :: CanonicalPath -> Text+cpathToText = pathToText . unsafePath+ -- | @'fromPrelude' fp'@ converts 'Prelude.FilePath' to 'UnsafePath'. -- -- /Since 0.1.0.0/@@ -232,3 +267,6 @@ -- /Since 0.1.0.0/ toPrelude :: UnsafePath -> Prelude.FilePath toPrelude = Text.unpack . pathToText++voidM :: Monad m => m a -> m ()+voidM a = a >> return ()
changelog.md view
@@ -1,11 +1,24 @@-0.1.2.0- * add writeFile'- * add some type conversion functions- * update documentation+0.2.3.0:+* add `cpathToText` that converts `CanonicalPath` to `Text`+* update base version constraints +0.2.2.0:+* add functions that return unit instead of `CanonicalPath` to `Directory` module++0.2.1.0:+* add `CanonicalPath` constructors that works with `Text` instead of `UnsafePath`++0.2.0.0:+* most of functions are in `MonadIO m` now instead of `IO`++0.1.2.0:+* add writeFile'+* add some type conversion functions+* update documentation+ 0.1.1.0:- * Filesystem.CanonicalPath.Directory implementation- * Add documentation+* Filesystem.CanonicalPath.Directory implementation+* Add documentation 0.1.0.0:- * Initial implementation of library+* Initial implementation of library
system-canonicalpath.cabal view
@@ -1,5 +1,5 @@ name: system-canonicalpath-version: 0.2.0.0+version: 0.2.3.0 synopsis: Abstract data type for canonical paths with pretty operations description: This library provides abstract data type named 'CanonicalPath' and some useful functions for working with it. See every module's description to find out more. homepage: https://github.com/d12frosted/CanonicalPath@@ -21,7 +21,7 @@ other-extensions: OverloadedStrings - build-depends: base >=4.7 && <4.8+ build-depends: base >=4.7 && < 4.9 , basic-prelude , directory , system-filepath