on master help sign in
Merge pull request #706 from dgaw/bugfix/tmp-cleanup-exception-catch
f901afbMichael Snoyman
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+
1## 3.0.24.0
5## 3.0.24.0
2
6
3* Add timeout middleware [#702](https://github.com/yesodweb/wai/pull/702).
7* 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)
59import Data.Function (on, fix)
59import Data.Function (on, fix)
60import System.Directory (removeFile, getTemporaryDirectory)
60import System.Directory (removeFile, getTemporaryDirectory)
61import System.IO (hClose, openBinaryTempFile)
61import System.IO (hClose, openBinaryTempFile)
62+import System.IO.Error (isDoesNotExistError)
62import Network.Wai
63import Network.Wai
63import qualified Network.HTTP.Types as H
64import qualified Network.HTTP.Types as H
64import Control.Applicative ((<$>))
65import Control.Applicative ((<$>))
66+import Control.Exception (catchJust)
65−import Control.Monad (when, unless)
67+import Control.Monad (when, unless, guard)
66import Control.Monad.Trans.Resource (allocate, release, register, InternalState, runInternalState)
68import Control.Monad.Trans.Resource (allocate, release, register, InternalState, runInternalState)
67import Data.IORef
69import Data.IORef
68import Network.HTTP.Types (hContentType)
70import Network.HTTP.Types (hContentType)
@@ -128,7 +130,7 @@ tempFileBackEndOpts :: IO FilePath -- ^ get temporary directory
128 -> IO FilePath
130 -> IO FilePath
129tempFileBackEndOpts getTmpDir pattrn internalState _ _ popper = do
131tempFileBackEndOpts getTmpDir pattrn internalState _ _ popper = do
130 (key, (fp, h)) <- flip runInternalState internalState $ allocate it (hClose . snd)
132 (key, (fp, h)) <- flip runInternalState internalState $ allocate it (hClose . snd)
131− _ <- runInternalState (register $ removeFile fp) internalState
133+ _ <- runInternalState (register $ removeFileQuiet fp) internalState
132 fix $ \loop -> do
134 fix $ \loop -> do
133 bs <- popper
135 bs <- popper
134 unless (S.null bs) $ do
136 unless (S.null bs) $ do
@@ -140,6 +142,9 @@ tempFileBackEndOpts getTmpDir pattrn internalState _ _ popper = do
140 it = do
142 it = do
141 tempDir <- getTmpDir
143 tempDir <- getTmpDir
142 openBinaryTempFile tempDir pattrn
144 openBinaryTempFile tempDir pattrn
145+ removeFileQuiet fp = catchJust (guard . isDoesNotExistError)
146+ (removeFile fp)
147+ (const $ return ())
143
148
144-- | A data structure that describes the behavior of
149-- | A data structure that describes the behavior of
145-- the parseRequestBodyEx function.
150-- the parseRequestBodyEx function.
wai-extra/wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
1Name: wai-extra
1Name: wai-extra
2−Version: 3.0.24.0
2+Version: 3.0.24.1
3Synopsis: Provides some basic WAI handlers and middleware.
3Synopsis: Provides some basic WAI handlers and middleware.
4description:
4description:
5 Provides basic WAI handler and middleware functionality:
5 Provides basic WAI handler and middleware functionality: