summaryrefslogtreecommitdiff
path: root/Utility/CopyFile.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utility/CopyFile.hs')
-rw-r--r--Utility/CopyFile.hs25
1 files changed, 22 insertions, 3 deletions
diff --git a/Utility/CopyFile.hs b/Utility/CopyFile.hs
index 18290669d..bb0600aa9 100644
--- a/Utility/CopyFile.hs
+++ b/Utility/CopyFile.hs
@@ -1,11 +1,16 @@
-{- git-annex file copying
+{- file copying
-
- - Copyright 2010,2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
-module Utility.CopyFile (copyFileExternal) where
+{-# LANGUAGE CPP #-}
+
+module Utility.CopyFile (
+ copyFileExternal,
+ createLinkOrCopy
+) where
import Common
import qualified Build.SysConfig as SysConfig
@@ -23,3 +28,17 @@ copyFileExternal src dest = do
, (SysConfig.cp_a, Param "-a")
, (SysConfig.cp_p && not SysConfig.cp_a, Param "-p")
]
+
+{- Create a hard link if the filesystem allows it, and fall back to copying
+ - the file. -}
+createLinkOrCopy :: FilePath -> FilePath -> IO Bool
+#ifndef __WINDOWS__
+createLinkOrCopy src dest = go `catchIO` const fallback
+ where
+ go = do
+ createLink src dest
+ return True
+ fallback = copyFileExternal src dest
+#else
+createLinkOrCopy = copyFileExternal
+#endif