From 7a8d7ba5ef558f3038ee5ee06e92e5f5e8df1ec5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 30 Nov 2017 13:45:43 -0400 Subject: rethought --relaxed change Better to make it not be surprising and slow, than surprising and fast. --raw can be used when it needs to be really fast. Implemented adding a youtube-dl supported url to an existing file. This commit was sponsored by andrea rota. --- Annex/Content.hs | 8 ++++---- Annex/YoutubeDl.hs | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'Annex') diff --git a/Annex/Content.hs b/Annex/Content.hs index 0899a12ab..4db5fda38 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -1017,10 +1017,10 @@ pruneTmpWorkDirBefore f action = do {- Runs an action, passing it a temporary work directory where - it can write files while receiving the content of a key. - - - On exception, or when the action returns a Left value, + - On exception, or when the action returns Nothing, - the temporary work directory is left, so resumes can use it. -} -withTmpWorkDir :: Key -> (FilePath -> Annex (Either a b)) -> Annex (Either a b) +withTmpWorkDir :: Key -> (FilePath -> Annex (Maybe a)) -> Annex (Maybe a) withTmpWorkDir key action = do -- Create the object file if it does not exist. This way, -- staleKeysPrune only has to look for object files, and can @@ -1034,8 +1034,8 @@ withTmpWorkDir key action = do setAnnexDirPerm tmpdir res <- action tmpdir case res of - Right _ -> liftIO $ removeDirectoryRecursive tmpdir - Left _ -> noop + Just _ -> liftIO $ removeDirectoryRecursive tmpdir + Nothing -> noop return res {- Finds items in the first, smaller list, that are not diff --git a/Annex/YoutubeDl.hs b/Annex/YoutubeDl.hs index 1eafa4173..4e33c2ff3 100644 --- a/Annex/YoutubeDl.hs +++ b/Annex/YoutubeDl.hs @@ -71,14 +71,12 @@ youtubeDlTo key url dest = do case dl of Right (Just mediafile) -> do liftIO $ renameFile mediafile dest - return (Right True) - Right Nothing -> return (Right False) - Left msg -> return (Left msg) - case res of - Left msg -> do - warning msg - return False - Right r -> return r + return (Just True) + Right Nothing -> return (Just False) + Left msg -> do + warning msg + return Nothing + return (fromMaybe False res) youtubeDlSupported :: URLString -> Annex Bool youtubeDlSupported url = either (const False) id <$> youtubeDlCheck url -- cgit v1.2.3