make --json-progress work for url downloads

This commit is contained in:
Joey Hess 2016-09-09 16:15:39 -04:00
parent 312ef4dfae
commit d4fbc3b460
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
2 changed files with 16 additions and 12 deletions

View file

@ -902,7 +902,7 @@ saveState nocommit = doSideAction $ do
{- Downloads content from any of a list of urls. -} {- Downloads content from any of a list of urls. -}
downloadUrl :: Key -> MeterUpdate -> [Url.URLString] -> FilePath -> Annex Bool downloadUrl :: Key -> MeterUpdate -> [Url.URLString] -> FilePath -> Annex Bool
downloadUrl k p urls file = concurrentMeteredFile file (Just p) k $ downloadUrl k p urls file = meteredFile file (Just p) k $
go =<< annexWebDownloadCommand <$> Annex.getGitConfig go =<< annexWebDownloadCommand <$> Annex.getGitConfig
where where
go Nothing = do go Nothing = do

View file

@ -75,25 +75,29 @@ metered othermeter key a = case keySize key of
Just om -> combineMeterUpdate m om Just om -> combineMeterUpdate m om
{- Use when the command's own progress output is preferred. {- Use when the command's own progress output is preferred.
- The command's output will be suppressed and git-annex's progress output - The command's output will be suppressed and git-annex's progress meter
- used for concurrent output, and json progress. -} - used for concurrent output, and json progress. -}
commandMetered :: Maybe MeterUpdate -> Key -> (MeterUpdate -> Annex a) -> Annex a commandMetered :: Maybe MeterUpdate -> Key -> (MeterUpdate -> Annex a) -> Annex a
commandMetered combinemeterupdate key a = commandMetered combinemeterupdate key a =
withMessageState $ \s -> case outputType s of withMessageState $ \s -> if needOutputMeter s
JSONOutput True -> usemeter then metered combinemeterupdate key a
NormalOutput | concurrentOutputEnabled s -> usemeter else a (fromMaybe nullMeterUpdate combinemeterupdate)
_ -> a (fromMaybe nullMeterUpdate combinemeterupdate)
where
usemeter = metered combinemeterupdate key a
{- Poll file size to display meter, but only for concurrent output. -} {- Poll file size to display meter, but only when concurrent output or
concurrentMeteredFile :: FilePath -> Maybe MeterUpdate -> Key -> Annex a -> Annex a - json progress needs the information. -}
concurrentMeteredFile file combinemeterupdate key a = meteredFile :: FilePath -> Maybe MeterUpdate -> Key -> Annex a -> Annex a
withMessageState $ \s -> if concurrentOutputEnabled s meteredFile file combinemeterupdate key a =
withMessageState $ \s -> if needOutputMeter s
then metered combinemeterupdate key $ \p -> then metered combinemeterupdate key $ \p ->
watchFileSize file p a watchFileSize file p a
else a else a
needOutputMeter :: MessageState -> Bool
needOutputMeter s = case outputType s of
JSONOutput True -> True
NormalOutput | concurrentOutputEnabled s -> True
_ -> False
{- Progress dots. -} {- Progress dots. -}
showProgressDots :: Annex () showProgressDots :: Annex ()
showProgressDots = outputMessage JSON.none "." showProgressDots = outputMessage JSON.none "."