improve tmp file cleanup

If youtubeDl fails, remove the tmp file. Here tmp is the
html file downloaded to check if the url is html, not what youtube-dl
might have started to download. If the tmp file were retained, a
re-run of addurl would try to resume downloading it, which the web
server might not support, causing the resume to fail.
And it's a smallish html page anyway so no benefit to
keeping it for such a resume.
This commit is contained in:
Joey Hess 2018-06-28 12:48:54 -04:00
parent 181e9019d3
commit 79ac177ea5
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -283,18 +283,20 @@ downloadWeb o url urlinfo file =
(dl dest)
Left _ -> normalfinish tmp
where
dl dest = withTmpWorkDir mediakey $ \workdir ->
dl dest = withTmpWorkDir mediakey $ \workdir -> do
let cleanuptmp = pruneTmpWorkDirBefore tmp (liftIO . nukeFile)
Transfer.notifyTransfer Transfer.Download url $
Transfer.download webUUID mediakey (AssociatedFile Nothing) Transfer.noRetry $ \_p ->
youtubeDl url workdir >>= \case
Right (Just mediafile) -> do
pruneTmpWorkDirBefore tmp (liftIO . nukeFile)
cleanuptmp
checkCanAdd dest $ do
showDestinationFile dest
addWorkTree webUUID mediaurl dest mediakey (Just mediafile)
return $ Just mediakey
Right Nothing -> normalfinish tmp
Left msg -> do
cleanuptmp
warning msg
return Nothing
mediaurl = setDownloader url YoutubeDownloader