store probed androidserial for later use by enableremote

This commit is contained in:
Joey Hess 2018-03-27 17:34:31 -04:00
parent bc90c71b54
commit ceee0ea5f1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -98,28 +98,30 @@ adbSetup _ mu _ c gc = do
adir <- maybe (giveup "Specify androiddirectory=") (pure . AndroidPath) adir <- maybe (giveup "Specify androiddirectory=") (pure . AndroidPath)
(M.lookup "androiddirectory" c) (M.lookup "androiddirectory" c)
serial <- getserial =<< liftIO enumerateAdbConnected serial <- getserial =<< liftIO enumerateAdbConnected
let c' = M.insert "androidserial" (fromAndroidSerial serial) c
(c', _encsetup) <- encryptionSetup c gc (c'', _encsetup) <- encryptionSetup c' gc
ok <- liftIO $ adbShellBool serial ok <- liftIO $ adbShellBool serial
[Param "mkdir", Param "-p", File (fromAndroidPath adir)] [Param "mkdir", Param "-p", File (fromAndroidPath adir)]
unless ok $ unless ok $
giveup "Creating directory on Android device failed." giveup "Creating directory on Android device failed."
gitConfigSpecialRemote u c' gitConfigSpecialRemote u c''
[ ("adb", "true") [ ("adb", "true")
, ("androiddirectory", fromAndroidPath adir) , ("androiddirectory", fromAndroidPath adir)
, ("androidserial", fromAndroidSerial serial) , ("androidserial", fromAndroidSerial serial)
] ]
return (c', u) return (c'', u)
where where
getserial [] = giveup "adb does not list any connected android devices. Plug in an Android device, or configure adb, and try again.." getserial [] = giveup "adb does not list any connected android devices. Plug in an Android device, or configure adb, and try again.."
getserial (s:[]) = return s
getserial l = case M.lookup "androidserial" c of getserial l = case M.lookup "androidserial" c of
Nothing -> giveup $ unlines $ Nothing -> case l of
"There are multiple connected android devices, specify which to use with androidserial=" (s:[]) -> return s
: map fromAndroidSerial l _ -> giveup $ unlines $
"There are multiple connected android devices, specify which to use with androidserial="
: map fromAndroidSerial l
Just cs Just cs
| AndroidSerial cs `elem` l -> return (AndroidSerial cs) | AndroidSerial cs `elem` l -> return (AndroidSerial cs)
| otherwise -> giveup $ "The device with androidserial=" ++ cs ++ " is not connected." | otherwise -> giveup $ "The device with androidserial=" ++ cs ++ " is not connected."