adb: Added ignorefinderror configuration parameter

On a phone with Calyxos, adb find in /sdcard complains:

find: ./Android/data/com.android.providers.downloads.ui: Permission denied

But otherwise works, so this option makes import and export work ok, except
for that one app's data.

Sponsored-by: Graham Spencer
This commit is contained in:
Joey Hess 2022-01-10 21:15:30 -04:00
parent 00a917d2d2
commit 525473aa5a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 24 additions and 7 deletions

View file

@ -9,6 +9,7 @@ git-annex (8.20211232) UNRELEASED; urgency=medium
by deleting the temporary file when it fails to verify. This prevents by deleting the temporary file when it fails to verify. This prevents
a retry from failing again. a retry from failing again.
(reversion introduced in version 8.20210903) (reversion introduced in version 8.20210903)
* adb: Added ignorefinderror configuration parameter.
-- Joey Hess <id@joeyh.name> Mon, 03 Jan 2022 14:01:14 -0400 -- Joey Hess <id@joeyh.name> Mon, 03 Jan 2022 14:01:14 -0400

View file

@ -43,6 +43,8 @@ remote = specialRemoteType $ RemoteType
(FieldDesc "location on the Android device where the files are stored") (FieldDesc "location on the Android device where the files are stored")
, optionalStringParser androidserialField , optionalStringParser androidserialField
(FieldDesc "sometimes needed to specify which Android device to use") (FieldDesc "sometimes needed to specify which Android device to use")
, yesNoParser ignorefinderrorField (Just False)
(FieldDesc "ignore adb find errors")
] ]
, setup = adbSetup , setup = adbSetup
, exportSupported = exportIsSupported , exportSupported = exportIsSupported
@ -56,6 +58,10 @@ androiddirectoryField = Accepted "androiddirectory"
androidserialField :: RemoteConfigField androidserialField :: RemoteConfigField
androidserialField = Accepted "androidserial" androidserialField = Accepted "androidserial"
ignorefinderrorField :: RemoteConfigField
ignorefinderrorField = Accepted "ignorefinderror"
gen :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> RemoteStateHandle -> Annex (Maybe Remote) gen :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> RemoteStateHandle -> Annex (Maybe Remote)
gen r u rc gc rs = do gen r u rc gc rs = do
c <- parsedRemoteConfig remote rc c <- parsedRemoteConfig remote rc
@ -83,7 +89,7 @@ gen r u rc gc rs = do
, renameExport = renameExportM serial adir , renameExport = renameExportM serial adir
} }
, importActions = ImportActions , importActions = ImportActions
{ listImportableContents = listImportableContentsM serial adir { listImportableContents = listImportableContentsM serial adir c
, importKey = Nothing , importKey = Nothing
, retrieveExportWithContentIdentifier = retrieveExportWithContentIdentifierM serial adir , retrieveExportWithContentIdentifier = retrieveExportWithContentIdentifierM serial adir
, storeExportWithContentIdentifier = storeExportWithContentIdentifierM serial adir , storeExportWithContentIdentifier = storeExportWithContentIdentifierM serial adir
@ -289,13 +295,13 @@ renameExportM serial adir _k old new = do
, File newloc , File newloc
] ]
listImportableContentsM :: AndroidSerial -> AndroidPath -> Annex (Maybe (ImportableContentsChunkable Annex (ContentIdentifier, ByteSize))) listImportableContentsM :: AndroidSerial -> AndroidPath -> ParsedRemoteConfig -> Annex (Maybe (ImportableContentsChunkable Annex (ContentIdentifier, ByteSize)))
listImportableContentsM serial adir = adbfind >>= \case listImportableContentsM serial adir c = adbfind >>= \case
Just ls -> return $ Just $ ImportableContentsComplete $ Just ls -> return $ Just $ ImportableContentsComplete $
ImportableContents (mapMaybe mk ls) [] ImportableContents (mapMaybe mk ls) []
Nothing -> giveup "adb find failed" Nothing -> giveup "adb find failed"
where where
adbfind = adbShell serial adbfind = adbShell' serial
[ Param "find" [ Param "find"
-- trailing slash is needed, or android's find command -- trailing slash is needed, or android's find command
-- won't recurse into the directory -- won't recurse into the directory
@ -305,6 +311,9 @@ listImportableContentsM serial adir = adbfind >>= \case
, Param "-c", Param statformat , Param "-c", Param statformat
, Param "{}", Param "+" , Param "{}", Param "+"
] ]
(if ignorefinderror then "|| true" else "")
ignorefinderror = fromMaybe False (getRemoteConfigValue ignorefinderrorField c)
statformat = adbStatFormat ++ "\t%n" statformat = adbStatFormat ++ "\t%n"
@ -390,8 +399,11 @@ enumerateAdbConnected = checkAdbInPath [] $ liftIO $
-- --
-- Any stdout from the command is returned, separated into lines. -- Any stdout from the command is returned, separated into lines.
adbShell :: AndroidSerial -> [CommandParam] -> Annex (Maybe [String]) adbShell :: AndroidSerial -> [CommandParam] -> Annex (Maybe [String])
adbShell serial cmd = adbShellRaw serial $ adbShell serial cmd = adbShell' serial cmd ""
unwords $ map shellEscape (toCommand cmd)
adbShell' :: AndroidSerial -> [CommandParam] -> String -> Annex (Maybe [String])
adbShell' serial cmd extra = adbShellRaw serial $
(unwords $ map shellEscape (toCommand cmd)) ++ extra
adbShellBool :: AndroidSerial -> [CommandParam] -> Annex Bool adbShellBool :: AndroidSerial -> [CommandParam] -> Annex Bool
adbShellBool serial cmd = adbShellBool serial cmd =

View file

@ -32,6 +32,10 @@ the adb remote.
by [[git-annex-import]]. When set in combination with exporttree, by [[git-annex-import]]. When set in combination with exporttree,
this lets files be imported from it, and changes exported back to it. this lets files be imported from it, and changes exported back to it.
* `ignorefinderror` - Set to "yes" to ignore errors when running "adb find"
on the Android device. This can be useful eg, if some subdirectories are
not readable, to let it import the other things that are readable.
* `encryption` - One of "none", "hybrid", "shared", or "pubkey". * `encryption` - One of "none", "hybrid", "shared", or "pubkey".
See [[encryption]]. See [[encryption]].