From a5cb4a7bc5d7d603fc8f5f8b1a1595e889fb25ce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 10 Jun 2013 13:10:30 -0400 Subject: 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. --- Utility/CopyFile.hs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'Utility/CopyFile.hs') 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 + - Copyright 2010-2013 Joey Hess - - 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 -- cgit v1.2.3