improve error display when storing to an export/import remote fails

Prompted by the test suite on windows failing to with "export foo failed"
and no information about what went wrong.

Note that only storeExportWithContentIdentifier has been converted.
storeExport still returns a Bool and so exceptions may be hidden.

However, storeExportWithContentIdentifier has many more failure modes,
since it needs to avoid overwriting modified files. So it's more
important it have better error display.
This commit is contained in:
Joey Hess 2019-08-13 12:05:00 -04:00
parent 05d52f9699
commit 5004381dd9
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 37 additions and 33 deletions

View file

@ -291,17 +291,19 @@ retrieveExportWithContentIdentifierM serial adir loc cid dest mkkey _p = catchDe
where
src = androidExportLocation adir loc
storeExportWithContentIdentifierM :: AndroidSerial -> AndroidPath -> FilePath -> Key -> ExportLocation -> [ContentIdentifier] -> MeterUpdate -> Annex (Maybe ContentIdentifier)
storeExportWithContentIdentifierM serial adir src _k loc overwritablecids _p = catchDefaultIO Nothing $
storeExportWithContentIdentifierM :: AndroidSerial -> AndroidPath -> FilePath -> Key -> ExportLocation -> [ContentIdentifier] -> MeterUpdate -> Annex (Either String 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)
( liftIO $ either (const Nothing) id
<$> getExportContentIdentifier serial adir loc
, return Nothing
( liftIO $ getExportContentIdentifier serial adir loc >>= return . \case
Right (Just cid) -> Right cid
Right Nothing -> Left "adb failed to store file"
Left _ -> Left "unable to get content identifier for file stored on adtb"
, return $ Left "adb failed to store file"
)
, return Nothing
, return $ Left "unsafe to overwrite file"
)
where
dest = androidExportLocation adir loc
@ -377,6 +379,7 @@ mkAdbCommand :: AndroidSerial -> [CommandParam] -> [CommandParam]
mkAdbCommand serial cmd = [Param "-s", Param (fromAndroidSerial serial)] ++ cmd
-- Gets the current content identifier for a file on the android device.
-- If the file is not present, returns Right Nothing
getExportContentIdentifier :: AndroidSerial -> AndroidPath -> ExportLocation -> IO (Either ExitCode (Maybe ContentIdentifier))
getExportContentIdentifier serial adir loc = liftIO $ do
ls <- adbShellRaw serial $ unwords