direct: Avoid leaving file content in misctemp if interrupted.
This commit is contained in:
parent
aa31a7182e
commit
bb6cec3461
4 changed files with 14 additions and 9 deletions
|
@ -39,7 +39,12 @@ replaceFileOr file action rollback = do
|
|||
return tmpfile
|
||||
go tmpfile = do
|
||||
action tmpfile
|
||||
liftIO $ catchIO (rename tmpfile file) (fallback tmpfile)
|
||||
fallback tmpfile _ = do
|
||||
createDirectoryIfMissing True $ parentDir file
|
||||
moveFile tmpfile file
|
||||
liftIO $ replaceFileFrom tmpfile file
|
||||
|
||||
replaceFileFrom :: FilePath -> FilePath -> IO ()
|
||||
replaceFileFrom src dest = go `catchIO` fallback
|
||||
where
|
||||
go = moveFile src dest
|
||||
fallback _ = do
|
||||
createDirectoryIfMissing True $ parentDir dest
|
||||
go
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue