Permalink
Browse files

factor out nukeFile

  • Loading branch information...
1 parent 723eb19 commit 993e6459a38817a9062aafae7552a668c2db7a31 @joeyh committed Jun 6, 2012
Showing with 13 additions and 9 deletions.
  1. +1 −1 Annex/Content.hs
  2. +3 −6 Command/Add.hs
  3. +1 −1 Command/DropUnused.hs
  4. +7 −0 Utility/Directory.hs
  5. +1 −1 git-union-merge.hs
View
@@ -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,
View
@@ -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
@@ -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
@@ -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
View
@@ -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

0 comments on commit 993e645

Please sign in to comment.