summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-18 13:48:28 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-18 13:49:01 -0400
commit161823d6eaff2adb7b99475b0edfe819fde11be1 (patch)
tree985788fced5af741d7da3b735876ba24e2b7f9d7
parent54513c69baffa40f2fcce42eb8651fdd98e05277 (diff)
Only use cp -a if it is supported, falling back to cp -p or plain cp.
* cp --reflink=auto is used if supported, and will make git annex unlock much faster on filesystems like btrfs that support copy of write.
-rw-r--r--Command/Unlock.hs7
-rw-r--r--CopyFile.hs24
-rw-r--r--Makefile2
-rw-r--r--Remotes.hs7
-rw-r--r--configure.hs18
-rw-r--r--debian/changelog6
-rw-r--r--doc/todo/use_cp_reflink.mdwn2
7 files changed, 48 insertions, 18 deletions
diff --git a/Command/Unlock.hs b/Command/Unlock.hs
index 3ff3023b2..34fde819c 100644
--- a/Command/Unlock.hs
+++ b/Command/Unlock.hs
@@ -8,7 +8,7 @@
module Command.Unlock where
import Control.Monad.State (liftIO)
-import System.Directory
+import System.Directory hiding (copyFile)
import Command
import qualified Annex
@@ -17,6 +17,7 @@ import Messages
import Locations
import Utility
import Core
+import CopyFile
seek :: [SubCmdSeek]
seek = [withFilesInGit start]
@@ -34,9 +35,9 @@ perform dest key = do
let src = annexLocation g key
liftIO $ removeFile dest
showNote "copying..."
- ok <- liftIO $ boolSystem "cp" ["-p", src, dest]
+ ok <- liftIO $ copyFile src dest
if ok
then do
liftIO $ allowWrite dest
return $ Just $ return True
- else error "cp failed!"
+ else error "copy failed!"
diff --git a/CopyFile.hs b/CopyFile.hs
new file mode 100644
index 000000000..39f1b0183
--- /dev/null
+++ b/CopyFile.hs
@@ -0,0 +1,24 @@
+{- git-annex file copying
+ -
+ - Copyright 2010 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module CopyFile (copyFile) where
+
+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 = boolSystem "cp" opts
+ where
+ opts = if (SysConfig.cp_reflink_auto)
+ then ["--reflink=auto", src, dest]
+ else if (SysConfig.cp_a)
+ then ["-a", src, dest]
+ else if (SysConfig.cp_p)
+ then ["-p", src, dest]
+ else [src, dest]
diff --git a/Makefile b/Makefile
index 685044146..17918f956 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ all: git-annex docs
ghcmake=ghc -Wall -odir build -hidir build -O2 --make
-SysConfig.hs:
+SysConfig.hs: configure.hs
$(ghcmake) configure
./configure
diff --git a/Remotes.hs b/Remotes.hs
index 7aad6c2a0..bf5ede572 100644
--- a/Remotes.hs
+++ b/Remotes.hs
@@ -23,7 +23,7 @@ import Control.Monad.State (liftIO)
import Control.Monad (filterM)
import qualified Data.Map as Map
import Data.String.Utils
-import System.Directory
+import System.Directory hiding (copyFile)
import System.Posix.Directory
import List
import Monad (when, unless)
@@ -37,6 +37,7 @@ import UUID
import Utility
import qualified Core
import Messages
+import CopyFile
{- Human visible list of remotes. -}
list :: [Git.Repo] -> String
@@ -204,7 +205,7 @@ copyFromRemote r key file = do
then getssh
else error "copying from non-ssh repo not supported"
where
- getlocal = liftIO $ boolSystem "cp" ["-a", keyloc, file]
+ getlocal = liftIO $ copyFile keyloc file
getssh = scp r [sshLocation r keyloc, file]
keyloc = annexLocation r key
@@ -219,7 +220,7 @@ copyToRemote r key file = do
then putssh keyloc
else error "copying to non-ssh repo not supported"
where
- putlocal src = liftIO $ boolSystem "cp" ["-a", src, file]
+ putlocal src = liftIO $ copyFile src file
putssh src = scp r [src, sshLocation r file]
sshLocation :: Git.Repo -> FilePath -> FilePath
diff --git a/configure.hs b/configure.hs
index fa07be3ab..56daf583a 100644
--- a/configure.hs
+++ b/configure.hs
@@ -1,5 +1,4 @@
-{- Checks system configuration and generates SysConfig.hs.
- -}
+{- Checks system configuration and generates SysConfig.hs. -}
import System.IO
import System.Cmd
@@ -12,8 +11,9 @@ data Config = Config String Bool
tests :: [TestDesc]
tests = [
- TestDesc "cp -a" "cp_a" cp_a
- , TestDesc "cp --reflink" "cp_reflink" cp_reflink
+ TestDesc "cp -a" "cp_a" $ testCp "-a"
+ , TestDesc "cp -p" "cp_p" $ testCp "-p"
+ , TestDesc "cp --reflink=auto" "cp_reflink_auto" $ testCp "--reflink=auto"
]
tmpDir :: String
@@ -25,11 +25,9 @@ testFile = tmpDir ++ "/testfile"
quiet :: String -> String
quiet s = s ++ " 2>/dev/null"
-cp_a :: Test
-cp_a = testCmd $ quiet $ "cp -a " ++ testFile ++ " " ++ testFile ++ ".new"
-
-cp_reflink :: Test
-cp_reflink = testCmd $ quiet $ "cp --reflink=auto " ++ testFile ++ " " ++ testFile ++ ".new"
+testCp :: String -> Test
+testCp option = testCmd $ quiet $ "cp " ++ option ++ " " ++ testFile ++
+ " " ++ testFile ++ ".new"
testCmd :: String -> Test
testCmd c = do
@@ -51,6 +49,7 @@ writeSysConfig config = do
header = [
"{- Automatically generated by configure. -}"
, "module SysConfig where"
+ , ""
]
footer = []
vars [] = []
@@ -58,6 +57,7 @@ writeSysConfig config = do
showvar (Config name val) = [
name ++ " :: Bool"
, name ++ " = " ++ show val
+ , ""
]
runTests :: [TestDesc] -> IO [Config]
diff --git a/debian/changelog b/debian/changelog
index e6549c1f0..21685ba4d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,8 +2,10 @@ git-annex (0.08) UNRELEASED; urgency=low
* Fix `git annex add ../foo` (when ran in a subdir of the repo).
* Add configure step to build process.
- * configure: Check to see if cp -a can be used.
- * configure: Check to see if cp --reflink=auto can be used.
+ * Only use cp -a if it is supported, falling back to cp -p or plain cp
+ as needed for portability.
+ * cp --reflink=auto is used if supported, and will make git annex unlock
+ much faster on filesystems like btrfs that support copy of write.
-- Joey Hess <joeyh@debian.org> Wed, 17 Nov 2010 13:54:49 -0400
diff --git a/doc/todo/use_cp_reflink.mdwn b/doc/todo/use_cp_reflink.mdwn
index d7974928c..39518abf1 100644
--- a/doc/todo/use_cp_reflink.mdwn
+++ b/doc/todo/use_cp_reflink.mdwn
@@ -3,3 +3,5 @@ The unlock command needs to copy a file, and it would be great to use this:
O(1) overhead on BTRFS. Needs coreutils 7.6; and remember that git-annex
may be used on systems without coreutils..
+
+[[done]]