Skip to content

Commit

Permalink
Fix ifdefs in Hakyll.Check
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Jan 23, 2017
1 parent 0790ebd commit 9557824
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/Hakyll/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ module Hakyll.Check


--------------------------------------------------------------------------------
import Control.Monad (forM_, foldM)
import Control.Monad.Reader (ask, ReaderT, runReaderT)
import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar,
readMVar)
import Control.Exception (SomeAsyncException (..),
SomeException (..), throw, try)
import Control.Monad (foldM, forM_)
import Control.Monad.Reader (ReaderT, ask, runReaderT)
import Control.Monad.State (StateT, get, modify, runStateT)
import Control.Monad.Trans (liftIO)
import Control.Monad.Trans.Resource (runResourceT)
import Data.ByteString.Char8 (unpack)
Expand All @@ -21,16 +26,11 @@ import System.Directory (doesDirectoryExist,
import System.Exit (ExitCode (..))
import System.FilePath (takeDirectory, takeExtension,
(</>))
import Control.Concurrent.MVar (MVar, newEmptyMVar, putMVar,
readMVar)
import qualified Text.HTML.TagSoup as TS


--------------------------------------------------------------------------------
#ifdef CHECK_EXTERNAL
import Control.Exception (SomeAsyncException (..),
SomeException (..), try, throw)
import Control.Monad.State (get, modify, StateT, runStateT)
import Data.List (intercalate)
import Data.Typeable (cast)
import Data.Version (versionBranch)
Expand Down Expand Up @@ -186,7 +186,7 @@ skip :: URL -> Maybe String -> Checker ()
skip url maybeReason = do
logger <- checkerLogger <$> ask
case maybeReason of
Nothing -> return ()
Nothing -> return ()
Just reason -> Logger.debug logger reason
putCheckResult url mempty {checkerOk = 1}

Expand Down Expand Up @@ -241,19 +241,14 @@ checkExternalUrl url = do
Left (SomeException e) ->
case (cast e :: Maybe SomeAsyncException) of
Just ae -> throw ae
_ -> faulty url (Just $ showException e)
_ -> faulty url (Just $ showException e)
Right _ -> ok url
where
-- Convert exception to a concise form
showException e = case cast e of
Just (Http.HttpExceptionRequest _ e') -> show e'
_ -> head $ words $ show e
#else
checkExternalUrl url = skip url Nothing
#endif
_ -> head $ words $ show e


--------------------------------------------------------------------------------
requestExternalUrl :: URL -> Checker (Either SomeException Bool)
requestExternalUrl url = liftIO $ try $ do
mgr <- Http.newManager Http.tlsManagerSettings
Expand All @@ -273,6 +268,9 @@ requestExternalUrl url = liftIO $ try $ do
-- Nice user agent info
ua = fromString $ "hakyll-check/" ++
(intercalate "." $ map show $ versionBranch Paths_hakyll.version)
#else
checkExternalUrl url = skip url Nothing
#endif


--------------------------------------------------------------------------------
Expand Down

0 comments on commit 9557824

Please sign in to comment.