summaryrefslogtreecommitdiff
path: root/Remote/Adb.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2023-09-11 13:13:05 -0400
committerJoey Hess <joeyh@joeyh.name>2023-09-11 13:13:05 -0400
commit29ae536637474dddd42d47e96d8fb300e4b1264d (patch)
treee68b8ab6a11d12c2e7ddd1367b7b673327cc68db /Remote/Adb.hs
parentc7346c2c470bc7727ff226a9ad8bc0d99218eb3a (diff)
adb send to final filename not tmp file
Avoids some problems with unusual character in exporttree filenames that confuse adb shell commands. In particular, with a filename that contains \351, adb push sends the file to the correct filename in /sdcard. And running find on the android device roundtrips the filename. But, running mv on that filename on the android device fails with "bad <filename>: No such file or directory". Interestingly, ls on android works, and rm fails. adb push to the final name to avoids this problem. But what about atomicity? Well, I tried an adb push and interrupted it part way through. The file was present while the push was running, but was removed once the push got interrupted. I also tried yanking the cable while adb push was running, and the partially received file was also deleted then. That avoids most problems. An import that runs at the same time as an export will see the partially sent file. But that is unlikely to be done, and if it did happen, it would notice that the imported file had changed in the meantime and discard it. Note that, since rm on the android device fails on these filenames, exporting a tree where the file is deleted is going to fail to remove it. I don't see what I can do about that, so long as android is using an rm that has issues with filename encodings. This was tested on a phone where find, ls, and rm all come from Toybox 0.8.6. Sponsored-by: unqueued on Patreon
Diffstat (limited to 'Remote/Adb.hs')
-rw-r--r--Remote/Adb.hs22
1 files changed, 4 insertions, 18 deletions
diff --git a/Remote/Adb.hs b/Remote/Adb.hs
index 7d4e38696a..214733080c 100644
--- a/Remote/Adb.hs
+++ b/Remote/Adb.hs
@@ -183,24 +183,12 @@ store serial adir = fileStorer $ \k src _p ->
giveup "adb failed"
store' :: AndroidSerial -> AndroidPath -> FilePath -> Annex Bool
-store' serial dest src = store'' serial dest src (return True)
-
-store'' :: AndroidSerial -> AndroidPath -> FilePath -> Annex Bool -> Annex Bool
-store'' serial dest src canoverwrite = checkAdbInPath False $ do
+store' serial dest src = checkAdbInPath False $ do
let destdir = takeDirectory $ fromAndroidPath dest
void $ adbShell serial [Param "mkdir", Param "-p", File destdir]
showOutput -- make way for adb push output
- let tmpdest = fromAndroidPath dest ++ ".annextmp"
- ifM (liftIO $ boolSystem "adb" (mkAdbCommand serial [Param "push", File src, File tmpdest]))
- ( ifM canoverwrite
- -- move into place atomically
- ( adbShellBool serial [Param "mv", File tmpdest, File (fromAndroidPath dest)]
- , do
- void $ remove' serial (AndroidPath tmpdest)
- return False
- )
- , return False
- )
+ liftIO $ boolSystem "adb" $ mkAdbCommand serial
+ [Param "push", File src, File (fromAndroidPath dest)]
retrieve :: AndroidSerial -> AndroidPath -> Retriever
retrieve serial adir = fileRetriever $ \dest k _p ->
@@ -385,10 +373,8 @@ retrieveExportWithContentIdentifierM serial adir loc cids dest gk _p = do
storeExportWithContentIdentifierM :: AndroidSerial -> AndroidPath -> FilePath -> Key -> ExportLocation -> [ContentIdentifier] -> MeterUpdate -> Annex ContentIdentifier
storeExportWithContentIdentifierM serial adir src _k loc overwritablecids _p =
- -- Check if overwrite is safe before sending, because sending the
- -- file is expensive and don't want to do it unncessarily.
ifM checkcanoverwrite
- ( ifM (store'' serial dest src checkcanoverwrite)
+ ( ifM (store' serial dest src)
( getExportContentIdentifier serial adir loc >>= \case
Right (Just cid) -> return cid
Right Nothing -> giveup "adb failed to store file"