Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

factor out nukeFile

  • Loading branch information...
commit 993e6459a38817a9062aafae7552a668c2db7a31 1 parent 723eb19
Joey Hess authored June 06, 2012
2  Annex/Content.hs
@@ -168,7 +168,7 @@ withTmp :: Key -> (FilePath -> Annex a) -> Annex a
168 168
 withTmp key action = do
169 169
 	tmp <- prepTmp key
170 170
 	res <- action tmp
171  
-	liftIO $ whenM (doesFileExist tmp) $ liftIO $ removeFile tmp
  171
+	liftIO $ nukeFile tmp
172 172
 	return res
173 173
 
174 174
 {- Checks that there is disk space available to store a given key,
9  Command/Add.hs
@@ -57,13 +57,10 @@ lockDown file = do
57 57
 	createAnnexDirectory tmp
58 58
 	pid <- liftIO getProcessID
59 59
 	let tmpfile = tmp </> "add" ++ show pid ++ "." ++ takeFileName file
60  
-	nuke tmpfile
  60
+	liftIO $ nukeFile tmpfile
61 61
 	liftIO $ createLink file tmpfile
62 62
 	return tmpfile
63 63
 
64  
-nuke :: FilePath -> Annex ()
65  
-nuke file = liftIO $ whenM (doesFileExist file) $ removeFile file
66  
-
67 64
 {- Moves the file into the annex. -}
68 65
 ingest :: FilePath -> Annex (Maybe Key)
69 66
 ingest file = do
@@ -75,7 +72,7 @@ ingest file = do
75 72
 		go _ Nothing = return Nothing
76 73
 		go tmpfile (Just (key, _)) = do
77 74
 			handle (undo file key) $ moveAnnex key tmpfile
78  
-			nuke file
  75
+			liftIO $ nukeFile file
79 76
 			return $ Just key
80 77
 
81 78
 perform :: FilePath -> CommandPerform
@@ -86,7 +83,7 @@ perform file = maybe stop (\key -> next $ cleanup file key True) =<< ingest file
86 83
 undo :: FilePath -> Key -> IOException -> Annex a
87 84
 undo file key e = do
88 85
 	whenM (inAnnex key) $ do
89  
-		nuke file
  86
+		liftIO $ nukeFile file
90 87
 		handle tryharder $ fromAnnex key file
91 88
 		logStatus key InfoMissing
92 89
 	throw e
2  Command/DropUnused.hs
@@ -40,5 +40,5 @@ perform key = maybe droplocal dropremote =<< Remote.byName =<< from
40 40
 performOther :: (Key -> Git.Repo -> FilePath) -> Key -> CommandPerform
41 41
 performOther filespec key = do
42 42
 	f <- fromRepo $ filespec key
43  
-	liftIO $ whenM (doesFileExist f) $ removeFile f
  43
+	liftIO $ nukeFile f
44 44
 	next $ return True
7  Utility/Directory.hs
@@ -88,6 +88,13 @@ moveFile src dest = tryIO (rename src dest) >>= onrename
88 88
 				(Left _) -> return False
89 89
 				(Right s) -> return $ isDirectory s
90 90
 
  91
+{- Removes a file, which may or may not exist.
  92
+ -
  93
+ - Note that an exception is thrown if the file exists but
  94
+ - cannot be removed. -}
  95
+nukeFile :: FilePath -> IO ()
  96
+nukeFile file = whenM (doesFileExist file) $ removeFile file
  97
+
91 98
 {- Runs an action in another directory. -}
92 99
 bracketCd :: FilePath -> IO a -> IO a
93 100
 bracketCd dir a = go =<< getCurrentDirectory
2  git-union-merge.hs
@@ -28,7 +28,7 @@ setup :: Git.Repo -> IO ()
28 28
 setup = cleanup -- idempotency
29 29
 
30 30
 cleanup :: Git.Repo -> IO ()
31  
-cleanup g = whenM (doesFileExist $ tmpIndex g) $ removeFile $ tmpIndex g
  31
+cleanup g = nukeFile $ tmpIndex g
32 32
 
33 33
 parseArgs :: IO [String]
34 34
 parseArgs = do

0 notes on commit 993e645

Please sign in to comment.
Something went wrong with that request. Please try again.