summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-02-19 14:56:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-02-19 14:57:45 -0400
commit4e40b54a7516bbc9070faaef31254bd22154684e (patch)
tree084161e52b8ceef67c193a0e43600bbf60c9aec4
parentae3b28eb5bfd70ef6f59069ec59abb13ca193d3d (diff)
Android: Support ssh connection caching.
-rw-r--r--Annex/Ssh.hs71
-rw-r--r--Build/Configure.hs1
-rw-r--r--debian/changelog1
-rw-r--r--git-annex.cabal2
-rw-r--r--standalone/android/Makefile4
-rwxr-xr-xstandalone/android/runshell7
6 files changed, 54 insertions, 32 deletions
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs
index b6811858f..444d534f6 100644
--- a/Annex/Ssh.hs
+++ b/Annex/Ssh.hs
@@ -1,6 +1,6 @@
{- git-annex ssh interface, with connection caching
-
- - Copyright 2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2012,2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -13,14 +13,15 @@ module Annex.Ssh (
) where
import qualified Data.Map as M
+import System.Posix.Env
import Common.Annex
import Annex.LockPool
import Annex.Perms
-#ifndef WITH_OLD_SSH
import qualified Build.SysConfig as SysConfig
import qualified Annex
-#endif
+import Config
+import Annex.UUID
{- Generates parameters to ssh to a given host (or user@host) on a given
- port, with connection caching. -}
@@ -40,33 +41,48 @@ sshParams (host, port) opts = go =<< sshInfo (host, port)
cleanstale = whenM (not . any isLock . M.keys <$> getPool) $
sshCleanup
+{- Returns a filename to use for a ssh connection caching socket, and
+ - parameters to enable ssh connection caching. -}
sshInfo :: (String, Maybe Integer) -> Annex (Maybe FilePath, [CommandParam])
-sshInfo (host, port) = ifM caching
- ( do
- dir <- fromRepo gitAnnexSshDir
+sshInfo (host, port) = go =<< sshCacheDir
+ where
+ go Nothing = return (Nothing, [])
+ go (Just dir) = do
let socketfile = dir </> hostport2socket host port
if valid_unix_socket_path socketfile
- then return (Just socketfile, cacheParams socketfile)
+ then return (Just socketfile, cacheparams socketfile)
else do
socketfile' <- liftIO $ relPathCwdToFile socketfile
if valid_unix_socket_path socketfile'
- then return (Just socketfile', cacheParams socketfile')
+ then return (Just socketfile', cacheparams socketfile')
else return (Nothing, [])
- , return (Nothing, [])
- )
+ cacheparams :: FilePath -> [CommandParam]
+ cacheparams socketfile =
+ [ Param "-S", Param socketfile
+ , Params "-o ControlMaster=auto -o ControlPersist=yes"
+ ]
+
+{- ssh connection caching creates sockets, so will not work on a
+ - crippled filesystem. A GIT_ANNEX_TMP_DIR can be provided to use
+ - a different filesystem. -}
+sshCacheDir :: Annex (Maybe FilePath)
+sshCacheDir
+ | SysConfig.sshconnectioncaching = ifM crippledFileSystem
+ ( maybe (return Nothing) usetmpdir =<< gettmpdir
+ , ifM (fromMaybe True . annexSshCaching <$> Annex.getGitConfig)
+ ( Just <$> fromRepo gitAnnexSshDir
+ , return Nothing
+ )
+ )
+ | otherwise = return Nothing
where
-#ifdef WITH_OLD_SSH
- caching = return False
-#else
- caching = fromMaybe SysConfig.sshconnectioncaching
- . annexSshCaching <$> Annex.getGitConfig
-#endif
-
-cacheParams :: FilePath -> [CommandParam]
-cacheParams socketfile =
- [ Param "-S", Param socketfile
- , Params "-o ControlMaster=auto -o ControlPersist=yes"
- ]
+ gettmpdir = liftIO $ getEnv "GIT_ANNEX_TMP_DIR"
+ usetmpdir tmpdir = do
+ u <- getUUID
+ let dir = tmpdir </> fromUUID u
+ liftIO $ catchMaybeIO $ do
+ createDirectoryIfMissing True dir
+ return $ dir
portParams :: Maybe Integer -> [CommandParam]
portParams Nothing = []
@@ -74,12 +90,13 @@ portParams (Just port) = [Param "-p", Param $ show port]
{- Stop any unused ssh processes. -}
sshCleanup :: Annex ()
-sshCleanup = do
- dir <- fromRepo gitAnnexSshDir
- sockets <- filter (not . isLock) <$>
- liftIO (catchDefaultIO [] $ dirContents dir)
- forM_ sockets cleanup
+sshCleanup = go =<< sshCacheDir
where
+ go Nothing = noop
+ go (Just dir) = do
+ sockets <- filter (not . isLock) <$>
+ liftIO (catchDefaultIO [] $ dirContents dir)
+ forM_ sockets cleanup
cleanup socketfile = do
-- Drop any shared lock we have, and take an
-- exclusive lock, without blocking. If the lock
diff --git a/Build/Configure.hs b/Build/Configure.hs
index b6e852d48..b6f2b773d 100644
--- a/Build/Configure.hs
+++ b/Build/Configure.hs
@@ -138,7 +138,6 @@ androidConfig c = overrides ++ filter (not . overridden) c
overrides =
[ Config "cp_reflink_auto" $ BoolConfig False
, Config "curl" $ BoolConfig False
- , Config "sshconnectioncaching" $ BoolConfig False
, Config "sha224" $ MaybeStringConfig Nothing
, Config "sha384" $ MaybeStringConfig Nothing
]
diff --git a/debian/changelog b/debian/changelog
index 584a03312..76c83056b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,7 @@ git-annex (3.20130217) UNRELEASED; urgency=low
* webapp: Can now add a new local repository, and make it sync with
the main local repository.
* Android: Bundle now includes openssh.
+ * Android: Support ssh connection caching.
-- Joey Hess <joeyh@debian.org> Sun, 17 Feb 2013 16:42:16 -0400
diff --git a/git-annex.cabal b/git-annex.cabal
index 5656be21b..b588a1321 100644
--- a/git-annex.cabal
+++ b/git-annex.cabal
@@ -1,5 +1,5 @@
Name: git-annex
-Version: 3.20130216.1
+Version: 3.20130217
Cabal-Version: >= 1.8
License: GPL
Maintainer: Joey Hess <joey@kitenet.net>
diff --git a/standalone/android/Makefile b/standalone/android/Makefile
index 177f91a12..13cbf2322 100644
--- a/standalone/android/Makefile
+++ b/standalone/android/Makefile
@@ -11,9 +11,9 @@ build: source
cd source/openssl && CC=$$(which cc) ./Configure android
cd source/openssl && $(MAKE)
- cd source/rsync && git reset --hard origin/master
+ cd source/openssh && git reset --hard
cd source/openssh && ./configure --host=arm-linux-androideabi --with-ssl-dir=../openssl --without-openssl-header-check
- cd source/openssh && patch < ../../openssh.patch
+ cd source/openssh && patch -p1 < ../../openssh.patch
cp openssh.config.h source/openssh/config.h
cd source/openssh && sed -i -e 's/getrrsetbyname.o //' openbsd-compat/Makefile
cd source/openssh && sed -i -e 's/auth-passwd.o //' Makefile
diff --git a/standalone/android/runshell b/standalone/android/runshell
index b2cb8ee2f..1b0b3e4f6 100755
--- a/standalone/android/runshell
+++ b/standalone/android/runshell
@@ -21,7 +21,7 @@ if [ ! -e "$base/bin/git" ]; then
fi
# Install busybox links.
-if [ ! -e "$base/bin/sh" ]; then
+if [ ! -e "$base/bin/sha256sum" ]; then
echo "(First run detected ... setting up busybox ...)"
"$base/bin/busybox" --install "$base/bin"
fi
@@ -53,6 +53,11 @@ export GIT_TEMPLATE_DIR
GIT_ANNEX_STANDLONE_ENV="PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR"
export GIT_ANNEX_STANDLONE_ENV
+# This is a temporary directory on a non-crippled filesystem.
+GIT_ANNEX_TMP_DIR=$base/tmp
+export GIT_ANNEX_TMP_DIR
+mkdir -p "$GIT_ANNEX_TMP_DIR"
+
if [ "$1" ]; then
cmd="$1"
shift 1