X-Git-Url: http://andersk.mit.edu/gitweb/scripts-static-cat.git/blobdiff_plain/1cb5cdb0bfd14a87fbf96171f25279aeede77c99..cee07ba63331e8b3dd39756a38fe4b913dfaffe0:/StaticCat.hs diff --git a/StaticCat.hs b/StaticCat.hs index 25be388..be7fbe0 100644 --- a/StaticCat.hs +++ b/StaticCat.hs @@ -131,13 +131,15 @@ serveFile file = (`catchExceptionCGI` outputMyError) $ do checkMethod $ do - h <- (`catchExceptionCGI` \e -> - if isDoesNotExistError e then throwExceptionCGI NotFound - else if isPermissionError e then throwExceptionCGI Forbidden - else throwExceptionCGI e) $ - liftIO $ openBinaryFile file ReadMode - (`catchCGI` \e -> - (liftIO $ hClose h) >> throwCGI e) $ do + let handleOpenError e = + if isDoesNotExistError e then throwExceptionCGI NotFound + else if isPermissionError e then throwExceptionCGI Forbidden + else throwExceptionCGI e + h <- liftIO (openBinaryFile file ReadMode) `catchExceptionCGI` handleOpenError + let handlePostOpenError e = do + liftIO $ hClose h + throwCGI e + (`catchCGI` handlePostOpenError) $ do status <- liftIO $ hGetStatus h let mTime = modificationTime status