Android: Support ssh connection caching.
This commit is contained in:
parent
4f41bd6ba6
commit
0f4cc559a7
6 changed files with 54 additions and 32 deletions
71
Annex/Ssh.hs
71
Annex/Ssh.hs
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex ssh interface, with connection caching
|
{- 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.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -13,14 +13,15 @@ module Annex.Ssh (
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
import System.Posix.Env
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Annex.LockPool
|
import Annex.LockPool
|
||||||
import Annex.Perms
|
import Annex.Perms
|
||||||
#ifndef WITH_OLD_SSH
|
|
||||||
import qualified Build.SysConfig as SysConfig
|
import qualified Build.SysConfig as SysConfig
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
#endif
|
import Config
|
||||||
|
import Annex.UUID
|
||||||
|
|
||||||
{- Generates parameters to ssh to a given host (or user@host) on a given
|
{- Generates parameters to ssh to a given host (or user@host) on a given
|
||||||
- port, with connection caching. -}
|
- port, with connection caching. -}
|
||||||
|
@ -40,33 +41,48 @@ sshParams (host, port) opts = go =<< sshInfo (host, port)
|
||||||
cleanstale = whenM (not . any isLock . M.keys <$> getPool) $
|
cleanstale = whenM (not . any isLock . M.keys <$> getPool) $
|
||||||
sshCleanup
|
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 :: (String, Maybe Integer) -> Annex (Maybe FilePath, [CommandParam])
|
||||||
sshInfo (host, port) = ifM caching
|
sshInfo (host, port) = go =<< sshCacheDir
|
||||||
( do
|
where
|
||||||
dir <- fromRepo gitAnnexSshDir
|
go Nothing = return (Nothing, [])
|
||||||
|
go (Just dir) = do
|
||||||
let socketfile = dir </> hostport2socket host port
|
let socketfile = dir </> hostport2socket host port
|
||||||
if valid_unix_socket_path socketfile
|
if valid_unix_socket_path socketfile
|
||||||
then return (Just socketfile, cacheParams socketfile)
|
then return (Just socketfile, cacheparams socketfile)
|
||||||
else do
|
else do
|
||||||
socketfile' <- liftIO $ relPathCwdToFile socketfile
|
socketfile' <- liftIO $ relPathCwdToFile socketfile
|
||||||
if valid_unix_socket_path socketfile'
|
if valid_unix_socket_path socketfile'
|
||||||
then return (Just socketfile', cacheParams socketfile')
|
then return (Just socketfile', cacheparams socketfile')
|
||||||
else return (Nothing, [])
|
else return (Nothing, [])
|
||||||
, return (Nothing, [])
|
cacheparams :: FilePath -> [CommandParam]
|
||||||
)
|
cacheparams socketfile =
|
||||||
where
|
[ Param "-S", Param socketfile
|
||||||
#ifdef WITH_OLD_SSH
|
, Params "-o ControlMaster=auto -o ControlPersist=yes"
|
||||||
caching = return False
|
]
|
||||||
#else
|
|
||||||
caching = fromMaybe SysConfig.sshconnectioncaching
|
|
||||||
. annexSshCaching <$> Annex.getGitConfig
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cacheParams :: FilePath -> [CommandParam]
|
{- ssh connection caching creates sockets, so will not work on a
|
||||||
cacheParams socketfile =
|
- crippled filesystem. A GIT_ANNEX_TMP_DIR can be provided to use
|
||||||
[ Param "-S", Param socketfile
|
- a different filesystem. -}
|
||||||
, Params "-o ControlMaster=auto -o ControlPersist=yes"
|
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
|
||||||
|
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 :: Maybe Integer -> [CommandParam]
|
||||||
portParams Nothing = []
|
portParams Nothing = []
|
||||||
|
@ -74,12 +90,13 @@ portParams (Just port) = [Param "-p", Param $ show port]
|
||||||
|
|
||||||
{- Stop any unused ssh processes. -}
|
{- Stop any unused ssh processes. -}
|
||||||
sshCleanup :: Annex ()
|
sshCleanup :: Annex ()
|
||||||
sshCleanup = do
|
sshCleanup = go =<< sshCacheDir
|
||||||
dir <- fromRepo gitAnnexSshDir
|
|
||||||
sockets <- filter (not . isLock) <$>
|
|
||||||
liftIO (catchDefaultIO [] $ dirContents dir)
|
|
||||||
forM_ sockets cleanup
|
|
||||||
where
|
where
|
||||||
|
go Nothing = noop
|
||||||
|
go (Just dir) = do
|
||||||
|
sockets <- filter (not . isLock) <$>
|
||||||
|
liftIO (catchDefaultIO [] $ dirContents dir)
|
||||||
|
forM_ sockets cleanup
|
||||||
cleanup socketfile = do
|
cleanup socketfile = do
|
||||||
-- Drop any shared lock we have, and take an
|
-- Drop any shared lock we have, and take an
|
||||||
-- exclusive lock, without blocking. If the lock
|
-- exclusive lock, without blocking. If the lock
|
||||||
|
|
|
@ -138,7 +138,6 @@ androidConfig c = overrides ++ filter (not . overridden) c
|
||||||
overrides =
|
overrides =
|
||||||
[ Config "cp_reflink_auto" $ BoolConfig False
|
[ Config "cp_reflink_auto" $ BoolConfig False
|
||||||
, Config "curl" $ BoolConfig False
|
, Config "curl" $ BoolConfig False
|
||||||
, Config "sshconnectioncaching" $ BoolConfig False
|
|
||||||
, Config "sha224" $ MaybeStringConfig Nothing
|
, Config "sha224" $ MaybeStringConfig Nothing
|
||||||
, Config "sha384" $ MaybeStringConfig Nothing
|
, Config "sha384" $ MaybeStringConfig Nothing
|
||||||
]
|
]
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -7,6 +7,7 @@ git-annex (3.20130217) UNRELEASED; urgency=low
|
||||||
* webapp: Can now add a new local repository, and make it sync with
|
* webapp: Can now add a new local repository, and make it sync with
|
||||||
the main local repository.
|
the main local repository.
|
||||||
* Android: Bundle now includes openssh.
|
* Android: Bundle now includes openssh.
|
||||||
|
* Android: Support ssh connection caching.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Sun, 17 Feb 2013 16:42:16 -0400
|
-- Joey Hess <joeyh@debian.org> Sun, 17 Feb 2013 16:42:16 -0400
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Name: git-annex
|
Name: git-annex
|
||||||
Version: 3.20130216.1
|
Version: 3.20130217
|
||||||
Cabal-Version: >= 1.8
|
Cabal-Version: >= 1.8
|
||||||
License: GPL
|
License: GPL
|
||||||
Maintainer: Joey Hess <joey@kitenet.net>
|
Maintainer: Joey Hess <joey@kitenet.net>
|
||||||
|
|
|
@ -11,9 +11,9 @@ build: source
|
||||||
cd source/openssl && CC=$$(which cc) ./Configure android
|
cd source/openssl && CC=$$(which cc) ./Configure android
|
||||||
cd source/openssl && $(MAKE)
|
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 && ./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
|
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/getrrsetbyname.o //' openbsd-compat/Makefile
|
||||||
cd source/openssh && sed -i -e 's/auth-passwd.o //' Makefile
|
cd source/openssh && sed -i -e 's/auth-passwd.o //' Makefile
|
||||||
|
|
|
@ -21,7 +21,7 @@ if [ ! -e "$base/bin/git" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install busybox links.
|
# Install busybox links.
|
||||||
if [ ! -e "$base/bin/sh" ]; then
|
if [ ! -e "$base/bin/sha256sum" ]; then
|
||||||
echo "(First run detected ... setting up busybox ...)"
|
echo "(First run detected ... setting up busybox ...)"
|
||||||
"$base/bin/busybox" --install "$base/bin"
|
"$base/bin/busybox" --install "$base/bin"
|
||||||
fi
|
fi
|
||||||
|
@ -53,6 +53,11 @@ export GIT_TEMPLATE_DIR
|
||||||
GIT_ANNEX_STANDLONE_ENV="PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR"
|
GIT_ANNEX_STANDLONE_ENV="PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR"
|
||||||
export GIT_ANNEX_STANDLONE_ENV
|
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
|
if [ "$1" ]; then
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
shift 1
|
shift 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue