diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-06 13:13:13 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-06 13:13:13 -0400 |
commit | 993e6459a38817a9062aafae7552a668c2db7a31 (patch) | |
tree | 900b38c923644d9f8b7eaf92ec240aa610551780 | |
parent | 723eb19bbf30d502cb6979655b8013de49ce0b5e (diff) |
factor out nukeFile
-rw-r--r-- | Annex/Content.hs | 2 | ||||
-rw-r--r-- | Command/Add.hs | 9 | ||||
-rw-r--r-- | Command/DropUnused.hs | 2 | ||||
-rw-r--r-- | Utility/Directory.hs | 7 | ||||
-rw-r--r-- | git-union-merge.hs | 2 |
5 files changed, 13 insertions, 9 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs index 26b332e24..232b43b2c 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -168,7 +168,7 @@ withTmp :: Key -> (FilePath -> Annex a) -> Annex a withTmp key action = do tmp <- prepTmp key res <- action tmp - liftIO $ whenM (doesFileExist tmp) $ liftIO $ removeFile tmp + liftIO $ nukeFile tmp return res {- Checks that there is disk space available to store a given key, diff --git a/Command/Add.hs b/Command/Add.hs index 7fbfa6e7f..d83817d72 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -57,13 +57,10 @@ lockDown file = do createAnnexDirectory tmp pid <- liftIO getProcessID let tmpfile = tmp </> "add" ++ show pid ++ "." ++ takeFileName file - nuke tmpfile + liftIO $ nukeFile tmpfile liftIO $ createLink file tmpfile return tmpfile -nuke :: FilePath -> Annex () -nuke file = liftIO $ whenM (doesFileExist file) $ removeFile file - {- Moves the file into the annex. -} ingest :: FilePath -> Annex (Maybe Key) ingest file = do @@ -75,7 +72,7 @@ ingest file = do go _ Nothing = return Nothing go tmpfile (Just (key, _)) = do handle (undo file key) $ moveAnnex key tmpfile - nuke file + liftIO $ nukeFile file return $ Just key perform :: FilePath -> CommandPerform @@ -86,7 +83,7 @@ perform file = maybe stop (\key -> next $ cleanup file key True) =<< ingest file undo :: FilePath -> Key -> IOException -> Annex a undo file key e = do whenM (inAnnex key) $ do - nuke file + liftIO $ nukeFile file handle tryharder $ fromAnnex key file logStatus key InfoMissing throw e diff --git a/Command/DropUnused.hs b/Command/DropUnused.hs index a94c2873d..597a4eec0 100644 --- a/Command/DropUnused.hs +++ b/Command/DropUnused.hs @@ -40,5 +40,5 @@ perform key = maybe droplocal dropremote =<< Remote.byName =<< from performOther :: (Key -> Git.Repo -> FilePath) -> Key -> CommandPerform performOther filespec key = do f <- fromRepo $ filespec key - liftIO $ whenM (doesFileExist f) $ removeFile f + liftIO $ nukeFile f next $ return True diff --git a/Utility/Directory.hs b/Utility/Directory.hs index 5bfd49a9c..52f2396d7 100644 --- a/Utility/Directory.hs +++ b/Utility/Directory.hs @@ -88,6 +88,13 @@ moveFile src dest = tryIO (rename src dest) >>= onrename (Left _) -> return False (Right s) -> return $ isDirectory s +{- Removes a file, which may or may not exist. + - + - Note that an exception is thrown if the file exists but + - cannot be removed. -} +nukeFile :: FilePath -> IO () +nukeFile file = whenM (doesFileExist file) $ removeFile file + {- Runs an action in another directory. -} bracketCd :: FilePath -> IO a -> IO a bracketCd dir a = go =<< getCurrentDirectory diff --git a/git-union-merge.hs b/git-union-merge.hs index 2c2e7a46b..0e4cd644c 100644 --- a/git-union-merge.hs +++ b/git-union-merge.hs @@ -28,7 +28,7 @@ setup :: Git.Repo -> IO () setup = cleanup -- idempotency cleanup :: Git.Repo -> IO () -cleanup g = whenM (doesFileExist $ tmpIndex g) $ removeFile $ tmpIndex g +cleanup g = nukeFile $ tmpIndex g parseArgs :: IO [String] parseArgs = do |