]> dgit.raspbian.org Git - git-annex.git/commitdiff
adb: Added ignorefinderror configuration parameter
authorJoey Hess <joeyh@joeyh.name>
Tue, 11 Jan 2022 01:15:30 +0000 (21:15 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 11 Jan 2022 01:17:00 +0000 (21:17 -0400)
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
CHANGELOG
Remote/Adb.hs
doc/special_remotes/adb.mdwn

index 79d655a6b430486c5615e0f78a4e3c617946520a..16cd4f00985d0154e851966c6e4525c3d411a86d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,7 @@ git-annex (8.20211232) UNRELEASED; urgency=medium
     by deleting the temporary file when it fails to verify. This prevents
     a retry from failing again. 
     (reversion introduced in version 8.20210903)
+  * adb: Added ignorefinderror configuration parameter.
 
  -- Joey Hess <id@joeyh.name>  Mon, 03 Jan 2022 14:01:14 -0400
 
index 580a640fc538ac5faeb111553b95b33ff7cadec8..2001727b11dcfdec354aeeee60db80a4b54bc9e6 100644 (file)
@@ -43,6 +43,8 @@ remote = specialRemoteType $ RemoteType
                        (FieldDesc "location on the Android device where the files are stored")
                , optionalStringParser androidserialField
                        (FieldDesc "sometimes needed to specify which Android device to use")
+               , yesNoParser ignorefinderrorField (Just False)
+                       (FieldDesc "ignore adb find errors")
                ]
        , setup = adbSetup
        , exportSupported = exportIsSupported
@@ -56,6 +58,10 @@ androiddirectoryField = Accepted "androiddirectory"
 androidserialField :: RemoteConfigField
 androidserialField = Accepted "androidserial"
 
+ignorefinderrorField :: RemoteConfigField
+ignorefinderrorField = Accepted "ignorefinderror"
+
+
 gen :: Git.Repo -> UUID -> RemoteConfig -> RemoteGitConfig -> RemoteStateHandle -> Annex (Maybe Remote)
 gen r u rc gc rs = do
        c <- parsedRemoteConfig remote rc
@@ -83,7 +89,7 @@ gen r u rc gc rs = do
                        , renameExport = renameExportM serial adir
                        }
                , importActions = ImportActions
-                       { listImportableContents = listImportableContentsM serial adir
+                       { listImportableContents = listImportableContentsM serial adir c
                        , importKey = Nothing
                        , retrieveExportWithContentIdentifier = retrieveExportWithContentIdentifierM serial adir
                        , storeExportWithContentIdentifier = storeExportWithContentIdentifierM serial adir
@@ -289,13 +295,13 @@ renameExportM serial adir _k old new = do
                , File newloc
                ]
 
-listImportableContentsM :: AndroidSerial -> AndroidPath -> Annex (Maybe (ImportableContentsChunkable Annex (ContentIdentifier, ByteSize)))
-listImportableContentsM serial adir = adbfind >>= \case
+listImportableContentsM :: AndroidSerial -> AndroidPath -> ParsedRemoteConfig -> Annex (Maybe (ImportableContentsChunkable Annex (ContentIdentifier, ByteSize)))
+listImportableContentsM serial adir c = adbfind >>= \case
        Just ls -> return $ Just $ ImportableContentsComplete $ 
                ImportableContents (mapMaybe mk ls) []
        Nothing -> giveup "adb find failed"
   where
-       adbfind = adbShell serial
+       adbfind = adbShell' serial
                [ Param "find"
                -- trailing slash is needed, or android's find command
                -- won't recurse into the directory
@@ -304,7 +310,10 @@ listImportableContentsM serial adir = adbfind >>= \case
                , Param "-exec", Param "stat"
                , Param "-c", Param statformat
                , Param "{}", Param "+"
-               ]
+               ] 
+               (if ignorefinderror then "|| true" else "")
+
+       ignorefinderror = fromMaybe False (getRemoteConfigValue ignorefinderrorField c)
 
        statformat = adbStatFormat ++ "\t%n"
 
@@ -390,8 +399,11 @@ enumerateAdbConnected = checkAdbInPath [] $ liftIO $
 --
 -- Any stdout from the command is returned, separated into lines.
 adbShell :: AndroidSerial -> [CommandParam] -> Annex (Maybe [String])
-adbShell serial cmd = adbShellRaw serial $
-       unwords $ map shellEscape (toCommand cmd)
+adbShell serial cmd = adbShell' serial 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 serial cmd =
index 4eed62daf3d866ce5ecae0ca1c1ecde3eb11a05b..44f0f79e90f183db60910b2570e179e6beadf97f 100644 (file)
@@ -32,6 +32,10 @@ the adb remote.
   by [[git-annex-import]]. When set in combination with exporttree,
   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".
   See [[encryption]].