summaryrefslogtreecommitdiff
path: root/Utility/CopyFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-07-05 20:24:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-07-05 20:24:10 -0400
commitc98b5cf36e785cdf2c971eaf9b0329db06b68ef8 (patch)
tree9f7e69b1a57bccdb0ef446035d6579fdd3938fe1 /Utility/CopyFile.hs
parent6040d8aed17de582f5d5c179040e29c599315e31 (diff)
rename
Diffstat (limited to 'Utility/CopyFile.hs')
-rw-r--r--Utility/CopyFile.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Utility/CopyFile.hs b/Utility/CopyFile.hs
new file mode 100644
index 000000000..5ee4a91df
--- /dev/null
+++ b/Utility/CopyFile.hs
@@ -0,0 +1,29 @@
+{- git-annex file copying
+ -
+ - Copyright 2010 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Utility.CopyFile (copyFile) where
+
+import System.Directory (doesFileExist, removeFile)
+
+import Utility
+import qualified SysConfig
+
+{- The cp command is used, because I hate reinventing the wheel,
+ - and because this allows easy access to features like cp --reflink. -}
+copyFile :: FilePath -> FilePath -> IO Bool
+copyFile src dest = do
+ whenM (doesFileExist dest) $
+ removeFile dest
+ boolSystem "cp" [params, File src, File dest]
+ where
+ params = if SysConfig.cp_reflink_auto
+ then Params "--reflink=auto"
+ else if SysConfig.cp_a
+ then Params "-a"
+ else if SysConfig.cp_p
+ then Params "-p"
+ else Params ""