| ... |
... |
@@ -133,7 +133,6 @@ import GHC.Stack (HasCallStack) |
|
133
|
133
|
import GHC.Data.List
|
|
134
|
134
|
|
|
135
|
135
|
import Control.Monad ( guard )
|
|
136
|
|
-import Control.Monad.IO.Class ( MonadIO, liftIO )
|
|
137
|
136
|
import System.IO.Error as IO ( isDoesNotExistError )
|
|
138
|
137
|
import System.Directory ( doesDirectoryExist, getModificationTime, renameFile )
|
|
139
|
138
|
import qualified System.Directory.OsPath as OsPath
|
| ... |
... |
@@ -1273,8 +1272,8 @@ fileHashIfExists f = |
|
1273
|
1272
|
-- and uses their modification time to skip work later,
|
|
1274
|
1273
|
-- as otherwise a partially written file (e.g. due to crash or Ctrl+C)
|
|
1275
|
1274
|
-- also results in a skip.
|
|
1276
|
|
-
|
|
1277
|
|
-withAtomicRename :: (MonadIO m) => FilePath -> (FilePath -> m a) -> m a
|
|
|
1275
|
+{-# INLINE withAtomicRename #-}
|
|
|
1276
|
+withAtomicRename :: FilePath -> (FilePath -> IO ()) -> IO ()
|
|
1278
|
1277
|
withAtomicRename targetFile f = do
|
|
1279
|
1278
|
-- The temp file must be on the same file system (mount) as the target file
|
|
1280
|
1279
|
-- to result in an atomic move on most platforms.
|
| ... |
... |
@@ -1282,9 +1281,8 @@ withAtomicRename targetFile f = do |
|
1282
|
1281
|
-- This can still be fooled when somebody mounts a different file system
|
|
1283
|
1282
|
-- at just the right time, but that is not a case we aim to cover here.
|
|
1284
|
1283
|
let temp = targetFile <.> "tmp"
|
|
1285
|
|
- res <- f temp
|
|
1286
|
|
- liftIO $ renameFile temp targetFile
|
|
1287
|
|
- return res
|
|
|
1284
|
+ f temp
|
|
|
1285
|
+ renameFile temp targetFile
|
|
1288
|
1286
|
|
|
1289
|
1287
|
-- --------------------------------------------------------------
|
|
1290
|
1288
|
-- split a string at the last character where 'pred' is True,
|