on master help sign in
Merge pull request #706 from dgaw/bugfix/tmp-cleanup-exception-catch

wai-extra: Catch the "file not found" exception in tempFileBackEndOpt…

commitf901afb90d5d1ffdd921c37da2aeca963192d6f7 authorMichael Snoyman <michael@snoyman.com> dateTue 14 Aug 2018, 20:08 (8 years ago) parent03555020f99969
3 files changed+12−3
wai-extra/ChangeLog.md+4 wai-extra/Network/Wai/Parse.hs+7−2 wai-extra/wai-extra.cabal+1−1
wai-extra/ChangeLog.md+4
@@ -1,3 +1,7 @@
1+## 3.0.24.1
2+
3+* Fix a "file not found" exception in wai-extra [#705](https://github.com/yesodweb/wai/pull/706)
4+
15## 3.0.24.0
26
37* Add timeout middleware [#702](https://github.com/yesodweb/wai/pull/702).
wai-extra/Network/Wai/Parse.hs+7−2
@@ -59,10 +59,12 @@ import Data.List (sortBy)
5959import Data.Function (on, fix)
6060import System.Directory (removeFile, getTemporaryDirectory)
6161import System.IO (hClose, openBinaryTempFile)
62+import System.IO.Error (isDoesNotExistError)
6263import Network.Wai
6364import qualified Network.HTTP.Types as H
6465import Control.Applicative ((<$>))
65−import Control.Monad (when, unless)
66+import Control.Exception (catchJust)
67+import Control.Monad (when, unless, guard)
6668import Control.Monad.Trans.Resource (allocate, release, register, InternalState, runInternalState)
6769import Data.IORef
6870import Network.HTTP.Types (hContentType)
@@ -128,7 +130,7 @@ tempFileBackEndOpts :: IO FilePath -- ^ get temporary directory
128130 -> IO FilePath
129131tempFileBackEndOpts getTmpDir pattrn internalState _ _ popper = do
130132 (key, (fp, h)) <- flip runInternalState internalState $ allocate it (hClose . snd)
131− _ <- runInternalState (register $ removeFile fp) internalState
133+ _ <- runInternalState (register $ removeFileQuiet fp) internalState
132134 fix $ \loop -> do
133135 bs <- popper
134136 unless (S.null bs) $ do
@@ -140,6 +142,9 @@ tempFileBackEndOpts getTmpDir pattrn internalState _ _ popper = do
140142 it = do
141143 tempDir <- getTmpDir
142144 openBinaryTempFile tempDir pattrn
145+ removeFileQuiet fp = catchJust (guard . isDoesNotExistError)
146+ (removeFile fp)
147+ (const $ return ())
143148
144149-- | A data structure that describes the behavior of
145150-- the parseRequestBodyEx function.
wai-extra/wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
11Name: wai-extra
2−Version: 3.0.24.0
2+Version: 3.0.24.1
33Synopsis: Provides some basic WAI handlers and middleware.
44description:
55 Provides basic WAI handler and middleware functionality: