diff options
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/CopyFile.hs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/Utility/CopyFile.hs b/Utility/CopyFile.hs index e3ccd0a2b..6601d0a80 100644 --- a/Utility/CopyFile.hs +++ b/Utility/CopyFile.hs @@ -1,6 +1,6 @@ {- file copying - - - Copyright 2010-2013 Joey Hess <joey@kitenet.net> + - Copyright 2010-2014 Joey Hess <joey@kitenet.net> - - License: BSD-2-clause -} @@ -9,16 +9,20 @@ module Utility.CopyFile ( copyFileExternal, - createLinkOrCopy + createLinkOrCopy, + CopyMetaData(..) ) where import Common import qualified Build.SysConfig as SysConfig +data CopyMetaData = CopyTimeStamps | CopyAllMetaData + deriving (Eq) + {- The cp command is used, because I hate reinventing the wheel, - and because this allows easy access to features like cp --reflink. -} -copyFileExternal :: FilePath -> FilePath -> IO Bool -copyFileExternal src dest = do +copyFileExternal :: CopyMetaData -> FilePath -> FilePath -> IO Bool +copyFileExternal meta src dest = do whenM (doesFileExist dest) $ removeFile dest boolSystem "cp" $ params ++ [File src, File dest] @@ -26,12 +30,16 @@ copyFileExternal src dest = do #ifndef __ANDROID__ params = map snd $ filter fst [ (SysConfig.cp_reflink_auto, Param "--reflink=auto") - , (SysConfig.cp_a, Param "-a") - , (SysConfig.cp_p && not SysConfig.cp_a, Param "-p") + , (allmeta && SysConfig.cp_a, Param "-a") + , (allmeta && SysConfig.cp_p && not SysConfig.cp_a + , Param "-p") + , (not allmeta && SysConfig.cp_preserve_timestamps + , Param "--preserve=timestamps") ] #else params = [] #endif + allmeta = meta == CopyAllMetaData {- Create a hard link if the filesystem allows it, and fall back to copying - the file. -} @@ -42,7 +50,7 @@ createLinkOrCopy src dest = go `catchIO` const fallback go = do createLink src dest return True - fallback = copyFileExternal src dest + fallback = copyFileExternal CopyAllMetaData src dest #else -createLinkOrCopy = copyFileExternal +createLinkOrCopy = copyFileExternal CopyAllMetaData #endif |