small optimisation to file copying
Avoid statting file, just try to remove it. Also a comment to explain why it tries to remove it, which was puzzling me when I revisited this code until I saw that cp fails to overwrite a mode 444 file, including perhaps one left by a previous interrupted cp. This commit was sponsored by Fernando Jimenez on Patreon.
This commit is contained in:
parent
21ff5e1e5a
commit
7234b1f9a7
1 changed files with 4 additions and 4 deletions
|
@ -38,8 +38,9 @@ copyMetaDataParams meta = map snd $ filter fst
|
|||
- and because this allows easy access to features like cp --reflink. -}
|
||||
copyFileExternal :: CopyMetaData -> FilePath -> FilePath -> IO Bool
|
||||
copyFileExternal meta src dest = do
|
||||
whenM (doesFileExist dest) $
|
||||
removeFile dest
|
||||
-- Delete any existing dest file because an unwritable file
|
||||
-- would prevent cp from working.
|
||||
void $ tryIO $ removeFile dest
|
||||
boolSystem "cp" $ params ++ [File src, File dest]
|
||||
where
|
||||
params
|
||||
|
@ -52,8 +53,7 @@ copyFileExternal meta src dest = do
|
|||
copyCoW :: CopyMetaData -> FilePath -> FilePath -> IO Bool
|
||||
copyCoW meta src dest
|
||||
| BuildInfo.cp_reflink_supported = do
|
||||
whenM (doesFileExist dest) $
|
||||
removeFile dest
|
||||
void $ tryIO $ removeFile dest
|
||||
-- When CoW is not supported, cp will complain to stderr,
|
||||
-- so have to discard its stderr.
|
||||
ok <- catchBoolIO $ do
|
||||
|
|
Loading…
Reference in a new issue