plan-b 0.1.1 → 0.2.0
raw patch · 5 files changed
+48/−13 lines, 5 filesdep ~plan-b
Dependency ranges changed: plan-b
Files
- CHANGELOG.md +6/−0
- README.md +3/−0
- System/PlanB.hs +26/−10
- System/PlanB/Type.hs +11/−1
- plan-b.cabal +2/−2
CHANGELOG.md view
@@ -1,3 +1,9 @@+## Plan B 0.2.0++* Added `moveByRenaming` option to allow move files and directories by+ renaming. This is not default because moving by renaming is not always+ possible, while moving by coping is always an option.+ ## Plan B 0.1.1 * Fixed the problem with moving of files and directories from `/tmp/` to
README.md view
@@ -71,6 +71,9 @@ inspected. However, if operation succeeds, temporary directory is *always* deleted. +* `moveByRenaming` — by default files and directories are moved by copying,+ this option enables moving by renaming.+ That should be enough for a quick intro, for more information regarding concrete functions, consult Haddocks.
System/PlanB.hs view
@@ -28,6 +28,7 @@ , tempDir , nameTemplate , preserveCorpse+ , moveByRenaming , overrideIfExists , useIfExists ) where@@ -35,6 +36,7 @@ import Control.Monad import Control.Monad.Catch import Control.Monad.IO.Class (MonadIO (..))+import Data.Bool (bool) import Data.Maybe (fromMaybe) import Path import System.IO.Error@@ -61,7 +63,7 @@ withNewFile pbc fpath action = withTempDir pbc $ \tdir -> do let apath = constructFilePath tdir fpath checkExistenceOfFile pbc apath fpath- liftM2 const (action apath) (P.copyFile apath fpath)+ liftM2 const (action apath) (moveFile pbc apath fpath) -- | Edit existing file. Name of the file is taken as the second -- argument. The third argument allows to perform actions on temporary copy@@ -78,7 +80,7 @@ withExistingFile pbc fpath action = withTempDir pbc $ \tdir -> do let apath = constructFilePath tdir fpath copyFile fpath apath- liftM2 const (action apath) (P.copyFile apath fpath)+ liftM2 const (action apath) (moveFile pbc apath fpath) ---------------------------------------------------------------------------- -- Operations on directories@@ -98,7 +100,7 @@ -> m a withNewDir pbc dpath action = withTempDir pbc $ \tdir -> do checkExistenceOfDir pbc tdir dpath- liftM2 const (action tdir) (copyDir' tdir dpath)+ liftM2 const (action tdir) (moveDir pbc tdir dpath) -- | Edit existing directory. Name of the directory is specified as the -- second argument. The third argument allows to perform actions in@@ -114,7 +116,7 @@ -> m a withExistingDir pbc dpath action = withTempDir pbc $ \tdir -> do copyDir dpath tdir- liftM2 const (action tdir) (copyDir' tdir dpath)+ liftM2 const (action tdir) (moveDir pbc tdir dpath) ---------------------------------------------------------------------------- -- Operations on containers@@ -246,17 +248,31 @@ Just AebOverride -> return () Just AebUse -> copyDir dpath apath --- | Copy specified directory to another location. If destination location--- is already occupied, delete that object first.+-- | Move specified file to another location. File can be moved either by+-- copying or by renaming, exact method is determined by supplied+-- configuration. -copyDir' :: (MonadIO m, MonadCatch m)- => Path b0 Dir -- ^ Original location+moveFile :: (HasTemp c, MonadIO m)+ => c -- ^ Configuration+ -> Path b0 File -- ^ Original location+ -> Path b1 File -- ^ Where to move+ -> m ()+moveFile pbc = bool P.copyFile P.renameFile (getMoveByRenaming pbc)++-- | Move specified directory to another location. If destination location+-- is already occupied, delete that object first. Directory can be moved+-- either by copying or by renaming, exact method is determined by supplied+-- configuration.++moveDir :: (HasTemp c, MonadIO m, MonadCatch m)+ => c -- ^ Configuration+ -> Path b0 Dir -- ^ Original location -> Path b1 Dir -- ^ Where to move -> m ()-copyDir' src dest = do+moveDir pbc src dest = do exists <- P.doesDirExist dest when exists (P.removeDirRecur dest)- P.copyDirRecur src dest+ bool P.copyDirRecur P.renameDir (getMoveByRenaming pbc) src dest -- | Copy file to new location. Throw 'doesNotExistErrorType' if it does not -- exist.
System/PlanB/Type.hs view
@@ -54,15 +54,17 @@ { pbcTempDir :: Maybe (Path Abs Dir) , pbcNameTemplate :: Maybe String , pbcPreserveCorpse :: Any+ , pbcMoveByRenaming :: Any , pbcAlreadyExists :: Maybe AlreadyExistsBehavior } -> PbConfig k instance Monoid (PbConfig k) where- mempty = PbConfig empty empty mempty empty+ mempty = PbConfig empty empty mempty mempty empty x `mappend` y = PbConfig { pbcTempDir = pbcTempDir x <|> pbcTempDir y , pbcNameTemplate = pbcNameTemplate x <|> pbcNameTemplate y , pbcPreserveCorpse = pbcPreserveCorpse x <> pbcPreserveCorpse y+ , pbcMoveByRenaming = pbcMoveByRenaming x <> pbcMoveByRenaming y , pbcAlreadyExists = pbcAlreadyExists x <|> pbcAlreadyExists y } -- | The type class is for data types that include information specifying@@ -87,19 +89,27 @@ preserveCorpse :: c + -- | By default files are moved by copying. Moving by renaming, although+ -- not always possible, often more efficient. This option enables it.++ moveByRenaming :: c+ getTempDir :: c -> Maybe (Path Abs Dir) getNameTemplate :: c -> Maybe String getPreserveCorpse :: c -> Bool+ getMoveByRenaming :: c -> Bool instance HasTemp (PbConfig k) where tempDir dir = mempty { pbcTempDir = Just dir } nameTemplate nt = mempty { pbcNameTemplate = Just nt } preserveCorpse = mempty { pbcPreserveCorpse = Any True }+ moveByRenaming = mempty { pbcMoveByRenaming = Any True } getTempDir = pbcTempDir getNameTemplate = pbcNameTemplate getPreserveCorpse = getAny . pbcPreserveCorpse+ getMoveByRenaming = getAny . pbcMoveByRenaming -- | The type class includes data types that contain information about what -- to do when some object already exists. There are two scenarios currently
plan-b.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE. name: plan-b-version: 0.1.1+version: 0.2.0 cabal-version: >= 1.10 license: BSD3 license-file: LICENSE.md@@ -77,7 +77,7 @@ , hspec >= 2.0 , path >= 0.5 , path-io >= 1.0.1- , plan-b >= 0.1.1+ , plan-b >= 0.2.0 default-language: Haskell2010 source-repository head