aboutsummaryrefslogtreecommitdiff
path: root/Utility/CopyFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-08-26 17:06:43 -0700
committerGravatar Joey Hess <joey@kitenet.net>2014-08-26 17:10:25 -0700
commitf04fc3ca095f2372c9bb43ef5b884ed112d34eff (patch)
tree71b7b1ea09f7f1d7bf964544c1c04eb7259abf15 /Utility/CopyFile.hs
parent7924eb9422a949bbca80d7abc516eba0d9467f14 (diff)
Do not preserve permissions and acls when copying files from one local git repository to another. Timestamps are still preserved as long as cp --preserve=timestamps is supported.
This avoids cp -a overriding the default mode acls that the user might have set in a git repository. With GNU cp, this behavior change should not be a breaking change, because git-anex also uses rsync sometimes in the same situation, and has only ever preserved timestamps when using rsync. Systems without GNU cp will no longer use cp -a, but instead just cp. So, timestamps will no longer be preserved. Preserving timestamps when copying between repos is not guaranteed anyway. Closes: #729757
Diffstat (limited to 'Utility/CopyFile.hs')
-rw-r--r--Utility/CopyFile.hs24
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