factor out nukeFile
This commit is contained in:
parent
723eb19bbf
commit
993e6459a3
5 changed files with 13 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue