@@ -9,7 +9,7 @@ module System.File.OsPath.Internal where
99
1010import qualified System.File.Platform as P
1111
12- import Prelude ((.) , ($) , String , IO , ioError , pure , either , const , flip , Maybe (.. ), fmap , (<$>) , id , Bool (.. ), FilePath , (++) , return , show , (>>=) , (==) , otherwise , errorWithoutStackTrace , userError , mempty )
12+ import Prelude ((.) , ($) , String , IO , ioError , pure , either , const , flip , Maybe (.. ), fmap , (<$>) , id , Bool (.. ), FilePath , (++) , return , show , (>>=) , (==) , otherwise , userError )
1313import GHC.IO (catchException )
1414import GHC.IO.Exception (IOException (.. ))
1515import GHC.IO.Handle (hClose_help )
@@ -26,9 +26,10 @@ import System.OsString.Internal.Types
2626
2727import qualified Data.ByteString as BS
2828import qualified Data.ByteString.Lazy as BSL
29- import qualified System.OsString as OSS
3029import System.Posix.Types (CMode )
31- #if !MIN_VERSION_filepath(1, 5, 0)
30+ #if MIN_VERSION_filepath(1, 5, 0)
31+ import qualified System.OsString as OSS
32+ #else
3233import Data.Coerce
3334#endif
3435
@@ -245,46 +246,15 @@ openTempFile' loc (OsString tmp_dir) template@(OsString tmpl) binary mode
245246 -- We split off the last extension, so we can use .foo.ext files
246247 -- for temporary files (hidden on Unix OSes). Unfortunately we're
247248 -- below filepath in the hierarchy here.
248- (OsString prefix, OsString suffix) =
249- case break_ (== OSS. unsafeFromChar ' .' ) $ reverse_ template of
250- -- First case: template contains no '.'s. Just re-reverse it.
251- (rev_suffix, xs)
252- | xs == mempty -> (reverse_ rev_suffix, mempty )
253- -- Second case: template contains at least one '.'. Strip the
254- -- dot from the prefix and prepend it to the suffix (if we don't
255- -- do this, the unique number will get added after the '.' and
256- -- thus be part of the extension, which is wrong.)
257- (rev_suffix, xs)
258- | (h: rest) <- OSS. unpack xs
259- , h == unsafeFromChar ' .' -> (reverse_ (OSS. pack rest), cons_ (unsafeFromChar ' .' ) $ reverse_ rev_suffix)
260- -- Otherwise, something is wrong, because (break (== '.')) should
261- -- always return a pair with either the empty string or a string
262- -- beginning with '.' as the second component.
263- _ -> errorWithoutStackTrace " bug in System.IO.openTempFile"
249+ (OsString prefix, OsString suffix) = OSP. splitExtension template
264250
265251#if MIN_VERSION_filepath(1, 5, 0)
266252any_ :: (OsChar -> Bool ) -> OsString -> Bool
267253any_ = OSS. any
268254
269- cons_ :: OsChar -> OsString -> OsString
270- cons_ = OSS. cons
271-
272- break_ :: (OsChar -> Bool ) -> OsString -> (OsString , OsString )
273- break_ = OSS. break
274-
275- reverse_ :: OsString -> OsString
276- reverse_ = OSS. reverse
277255#else
278256any_ :: (OsChar -> Bool ) -> OsString -> Bool
279257any_ = coerce P. any_
280258
281- cons_ :: OsChar -> OsString -> OsString
282- cons_ = coerce P. cons_
283-
284- break_ :: (OsChar -> Bool ) -> OsString -> (OsString , OsString )
285- break_ = coerce P. break_
286-
287- reverse_ :: OsString -> OsString
288- reverse_ = coerce P. reverse_
289259#endif
290260
0 commit comments