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
|
||||
-
|
||||
- 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, [])
|
||||
)
|
||||
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"
|
||||
]
|
||||
|
||||
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
|
||||
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
|
||||
|
|
|
@ -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
|
||||
]
|
||||
|
|
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
|
||||
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
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue