path-io 0.2.0 → 0.3.0
raw patch · 3 files changed
+98/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Path.IO: getAccessTime :: MonadIO m => Path b t -> m UTCTime
- Path.IO: setAccessTime :: MonadIO m => Path b t -> UTCTime -> m ()
- Path.IO: setModificationTime :: MonadIO m => Path b t -> UTCTime -> m ()
+ Path.IO: forgivingAbsence :: (MonadIO m, MonadCatch m) => m a -> m (Maybe a)
+ Path.IO: forgivingAbsence' :: (MonadIO m, MonadCatch m) => m a -> m ()
+ Path.IO: makeRelative :: (AnyPath path, MonadThrow m) => Path Abs Dir -> path -> m (RelPath path)
+ Path.IO: makeRelativeToCurrentDir :: (AnyPath path, MonadIO m, MonadThrow m) => path -> m (RelPath path)
+ Path.IO: resolveDir :: (MonadIO m, MonadThrow m) => Path Abs Dir -> FilePath -> m (Path Abs Dir)
+ Path.IO: resolveDir' :: (MonadIO m, MonadThrow m) => FilePath -> m (Path Abs Dir)
+ Path.IO: resolveFile :: (MonadIO m, MonadThrow m) => Path Abs Dir -> FilePath -> m (Path Abs File)
+ Path.IO: resolveFile' :: (MonadIO m, MonadThrow m) => FilePath -> m (Path Abs File)
- Path.IO: getAppUserDataDir :: (MonadIO m, MonadThrow m) => Path File Dir -> m (Path Abs Dir)
+ Path.IO: getAppUserDataDir :: (MonadIO m, MonadThrow m) => Path Rel Dir -> m (Path Abs Dir)
Files
- CHANGELOG.md +11/−0
- Path/IO.hs +86/−4
- path-io.cabal +1/−1
CHANGELOG.md view
@@ -1,3 +1,14 @@+## Path IO 0.3.0++* Added `forgivingAbsence`, `resolveFile`, and `resolveDir` functions, so+ the package now provides all functionality that `Path.IO` module in Stack+ has.++* Added closed type family `RelPath`, `makeRelative`, and+ `makeRelativeToCurrentDir` functions.++* Fixed signature of `getAppUserDataDir`.+ ## Path IO 0.2.0 * Added functions from `temporary`: `withTempFile`, `withTempDir`,
Path/IO.hs view
@@ -37,7 +37,12 @@ , getTempDir -- * Path transformation , AbsPath+ , RelPath , AnyPath (..)+ , resolveFile+ , resolveFile'+ , resolveDir+ , resolveDir' -- * Actions on files , removeFile , renameFile@@ -58,6 +63,8 @@ , doesFileExist , doesDirExist , isLocationOccupied+ , forgivingAbsence+ , forgivingAbsence' -- * Permissions , D.Permissions , D.emptyPermissions@@ -91,6 +98,7 @@ import Data.Time (UTCTime) import Path import System.IO (Handle)+import System.IO.Error (isDoesNotExistError) import qualified System.Directory as D import qualified System.FilePath as F import qualified System.IO.Temp as T@@ -475,7 +483,7 @@ -- found. getAppUserDataDir :: (MonadIO m, MonadThrow m)- => Path File Dir -- ^ A relative path that is appended to the path+ => Path Rel Dir -- ^ A relative path that is appended to the path -> m (Path Abs Dir) getAppUserDataDir = (>>= parseAbsDir) . liftD D.getAppUserDataDirectory @@ -533,13 +541,20 @@ ---------------------------------------------------------------------------- -- Path transformation --- | Closed type-family describing how to get absolute version of given+-- | Closed type family describing how to get absolute version of given -- 'Path'. type family AbsPath path where AbsPath (Path b File) = Path Abs File AbsPath (Path b Dir) = Path Abs Dir +-- | Closed type family describing how to get relative version of given+-- 'Path'.++type family RelPath path where+ RelPath (Path b File) = Path Rel File+ RelPath (Path b Dir) = Path Rel Dir+ -- | Class of things ('Path's) that can be canonicalized and made absolute. class AnyPath path where@@ -572,7 +587,8 @@ -- -- /Known bug(s)/: on Windows, the function does not resolve symbolic links. - canonicalizePath :: (MonadIO m, MonadThrow m) => path -> m (AbsPath path)+ canonicalizePath :: (MonadIO m, MonadThrow m)+ => path -> m (AbsPath path) -- | Make a path absolute by prepending the current directory (if it isn't -- already absolute) and applying 'normalise' to the result.@@ -581,16 +597,68 @@ -- the operation may fail with the same exceptions as -- 'getCurrentDirectory'. - makeAbsolute :: (MonadIO m, MonadThrow m) => path -> m (AbsPath path)+ makeAbsolute :: (MonadIO m, MonadThrow m)+ => path -> m (AbsPath path) + -- | Make a path relative to given directory.++ makeRelative :: MonadThrow m+ => Path Abs Dir -- ^ Base directory+ -> path -- ^ Path that will be made relative to base directory+ -> m (RelPath path)++ -- | Make a path relative to current working directory.++ makeRelativeToCurrentDir :: (MonadIO m, MonadThrow m)+ => path -> m (RelPath path)+ instance AnyPath (Path b File) where canonicalizePath = liftD D.canonicalizePath >=> parseAbsFile makeAbsolute = liftD D.makeAbsolute >=> parseAbsFile+ makeRelative b p = parseRelFile (F.makeRelative (toFilePath b) (toFilePath p))+ makeRelativeToCurrentDir p = getCurrentDir >>= flip makeRelative p instance AnyPath (Path b Dir) where canonicalizePath = liftD D.canonicalizePath >=> parseAbsDir makeAbsolute = liftD D.makeAbsolute >=> parseAbsDir+ makeRelative b p = parseRelDir (F.makeRelative (toFilePath b) (toFilePath p))+ makeRelativeToCurrentDir p = getCurrentDir >>= flip makeRelative p +-- | Append stringly-typed path to an absolute path and then canonicalize+-- it. This can throw the same exceptions as 'canonicalizePath'. In+-- particular, 'System.IO.Error.doesNotExistErrorType' is thrown if+-- resulting file does not exist and thus its path cannot be canonicalized.++resolveFile :: (MonadIO m, MonadThrow m)+ => Path Abs Dir -- ^ Base directory+ -> FilePath -- ^ Path to resolve+ -> m (Path Abs File)+resolveFile b p = f (toFilePath b F.</> p) >>= parseAbsFile+ where f = liftIO . D.canonicalizePath++-- | The same as 'resolveFile', but uses current working directory.++resolveFile' :: (MonadIO m, MonadThrow m)+ => FilePath -- ^ Path to resolve+ -> m (Path Abs File)+resolveFile' p = getCurrentDir >>= flip resolveFile p++-- | The same as 'resolveFile', but for directories.++resolveDir :: (MonadIO m, MonadThrow m)+ => Path Abs Dir -- ^ Base directory+ -> FilePath -- ^ Path to resolve+ -> m (Path Abs Dir)+resolveDir b p = f (toFilePath b F.</> p) >>= parseAbsDir+ where f = liftIO . D.canonicalizePath++-- | The same as 'resolveDir', but uses current working directory.++resolveDir' :: (MonadIO m, MonadThrow m)+ => FilePath -- ^ Path to resolve+ -> m (Path Abs Dir)+resolveDir' p = getCurrentDir >>= flip resolveDir p+ ---------------------------------------------------------------------------- -- Actions on files @@ -879,6 +947,20 @@ file <- liftIO (D.doesFileExist fp) dir <- liftIO (D.doesDirectoryExist fp) return (file || dir)++-- | If argument of the function throws a+-- 'System.IO.Error.doesNotExistErrorType', 'Nothing' is returned (other+-- exceptions propagate). Otherwise the result is returned inside a 'Just'.++forgivingAbsence :: (MonadIO m, MonadCatch m) => m a -> m (Maybe a)+forgivingAbsence f = catchIf isDoesNotExistError+ (Just `liftM` f)+ (const $ return Nothing)++-- | The same as 'forgivingAbsence', but ignores result.++forgivingAbsence' :: (MonadIO m, MonadCatch m) => m a -> m ()+forgivingAbsence' = liftM (const ()) . forgivingAbsence ---------------------------------------------------------------------------- -- Permissions
path-io.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE. name: path-io-version: 0.2.0+version: 0.3.0 cabal-version: >= 1.10 license: BSD3 license-file: LICENSE.md