aboutsummaryrefslogtreecommitdiff
path: root/Utility/CopyFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-06-10 13:10:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-06-10 13:11:33 -0400
commita5cb4a7bc5d7d603fc8f5f8b1a1595e889fb25ce (patch)
tree9b1e97311129413c5e0d33e9b52caa0ab66809dc /Utility/CopyFile.hs
parent7bf5b7b0c5ba2789ef1473329da0000af0410b61 (diff)
Supports indirect mode on encfs in paranoia mode, and other filesystems that do not support hard links, but do support symlinks and other POSIX filesystem features.
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