From 39af078cc849372d62b8374781d2780fc81f9bca Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 12 Mar 2020 20:53:36 +1300 Subject: [PATCH] Fix app dispatch logic. Previously failed to build due to a file not listed in the build system. Previously crashed when trying to read a non-existant mimeapps file. --- hurl.cabal | 2 +- src/Network/URI/Fetch.hs | 7 +++---- src/Network/URI/XDG/MimeApps.hs | 8 +++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/hurl.cabal b/hurl.cabal index 1353b47..867bb13 100644 --- a/hurl.cabal +++ b/hurl.cabal @@ -104,4 +104,4 @@ library if flag(freedesktop) CPP-options: -DWITH_XDG build-depends: filepath, directory, process >= 1.2 && <2.0 - other-modules: Network.URI.XDG.Ini, Network.URI.XDG.MimeApps, Network.URI.XDG.DesktopEntry + other-modules: Network.URI.XDG.Ini, Network.URI.XDG.MimeApps, Network.URI.XDG.DesktopEntry, Network.URI.XDG diff --git a/src/Network/URI/Fetch.hs b/src/Network/URI/Fetch.hs index ac41f54..7727fb1 100644 --- a/src/Network/URI/Fetch.hs +++ b/src/Network/URI/Fetch.hs @@ -132,11 +132,10 @@ fetchURL Session {locale = l} _ URI {uriScheme = scheme} = dispatchByMIME :: Session -> String -> URI -> IO (Maybe String) #if WITH_XDG -dispatchByMIME Session {locale = l, apps = a} mime uri - | canDispatchMIME a mime = dispatchURIByMIME l a uri mime -#endif - +dispatchByMIME Session {locale = l, apps = a} mime uri = dispatchURIByMIME l a uri mime +#else dispatchByMIME _ _ _ = return Nothing +#endif #ifdef WITH_DATA_URI breakOn c (a:as) | c == a = ([], as) diff --git a/src/Network/URI/XDG/MimeApps.hs b/src/Network/URI/XDG/MimeApps.hs index 7fbad34..d2e9dde 100644 --- a/src/Network/URI/XDG/MimeApps.hs +++ b/src/Network/URI/XDG/MimeApps.hs @@ -2,6 +2,7 @@ module Network.URI.XDG.MimeApps(HandlersConfig, loadHandlers, queryHandlers, spl import System.Environment (lookupEnv) import Control.Monad (forM) +import Control.Exception (catch) import System.FilePath import Data.List (nub, (\\)) import System.Directory (getHomeDirectory) @@ -16,9 +17,14 @@ loadHandlers = do dir0 <- mimeAppsDirs "XDG_CONFIG" ".config" "/etc/xdg" dir1 <- mimeAppsDirs "XDG_DATA" ".local/share" "/usr/local/share/:/usr/share/" let filepaths = mimeAppsFiles (dir0 ++ map ( "applications") dir1) desktop - files <- forM filepaths readFile + files <- forM filepaths tryReadFile return $ map parseIni files +tryReadFile path = readFile path `catch` handler + where + handler :: IOError -> IO String + handler e = return "" + mimeAppsDirs envPrefix defaultHome defaultDirs = do home <- lookupEnv (envPrefix ++ "_HOME") dirs <- lookupEnv (envPrefix ++ "_DIRS") -- 2.30.2