diff --git a/CHANGELOG b/CHANGELOG index 0fb62325f5..8e1b0eb1f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ git-annex (6.20180720) UNRELEASED; urgency=medium for the git-annex branch instead of the usual "update". * Fix wrong sorting of remotes when using -J, it was sorting by uuid, rather than cost. + * addurl: Include filename in --json-progress output. -- Joey Hess Tue, 31 Jul 2018 12:14:11 -0400 diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 21a65746c1..d3f84a7bb2 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -126,7 +126,7 @@ checkUrl r o u = do where go _ (Left e) = void $ commandAction $ do - showStart' "addurl" (Just u) + showStartAddUrl u o warning (show e) next $ next $ return False go deffile (Right (UrlContents sz mf)) = do @@ -148,7 +148,7 @@ startRemote :: Remote -> AddUrlOptions -> FilePath -> URLString -> Maybe Integer startRemote r o file uri sz = do pathmax <- liftIO $ fileNameLengthLimit "." let file' = joinPath $ map (truncateFilePath pathmax) $ splitDirectories file - showStart' "addurl" (Just uri) + showStartAddUrl uri o showNote $ "from " ++ Remote.name r showDestinationFile file' next $ performRemote r o uri file' sz @@ -192,7 +192,7 @@ startWeb o urlstring = go $ fromMaybe bad $ parseURI urlstring bad = fromMaybe (giveup $ "bad url " ++ urlstring) $ Url.parseURIRelaxed $ urlstring go url = do - showStart' "addurl" (Just urlstring) + showStartAddUrl urlstring o pathmax <- liftIO $ fileNameLengthLimit "." urlinfo <- if relaxedOption (downloadOptions o) then pure Url.assumeUrlExists @@ -311,6 +311,15 @@ downloadWeb o url urlinfo file = warning $ dest ++ " already exists; not overwriting" return Nothing +{- The destination file is not known at start time unless the user provided + - a filename. It's not displayed then for output consistency, + - but is added to the json when available. -} +showStartAddUrl url o = do + showStart' "addurl" (Just url) + case fileOption (downloadOptions o) of + Nothing -> noop + Just file -> maybeShowJSON $ JSONChunk [("file", file)] + showDestinationFile :: FilePath -> Annex () showDestinationFile file = do showNote ("to " ++ file) diff --git a/doc/todo/provide___39__file__39___in_--json-progress_record_for_addurl.mdwn b/doc/todo/provide___39__file__39___in_--json-progress_record_for_addurl.mdwn index a68af9564e..12b4cd91ec 100644 --- a/doc/todo/provide___39__file__39___in_--json-progress_record_for_addurl.mdwn +++ b/doc/todo/provide___39__file__39___in_--json-progress_record_for_addurl.mdwn @@ -11,3 +11,9 @@ $> git annex addurl --file bigone --json --json-progress https://s3.amazonaws.co Thanks in advance [[!meta author=yoh]] + +> In general addurl doesn't know the filename until after it's downloaded +> the url (due to running youtube-dl on html urls), but when --file +> or --batch --with-files is used, it does know the filename early. +> So, made the json-progress include the filename when it's known. +> [[done]] --[[Joey]]