Ticket #7262: fix_build.2.patch

File fix_build.2.patch, 3.7 KB (added by sopvop, 7 years ago)
  • System/Directory.hs

    From 53963b2df9f6d8079b5887c09c6d28c53f53c6a2 Mon Sep 17 00:00:00 2001
    From: Leonid Onokhov <sopvop@gmail.com>
    Date: Sun, 23 Sep 2012 00:22:00 +0400
    Subject: [PATCH] Fix build for base < 4.6
    
    Build on 7.0.3 and up. Maybe lower.
    ---
     System/Directory.hs |   25 ++++++++++++++++---------
     1 file changed, 16 insertions(+), 9 deletions(-)
    
    diff --git a/System/Directory.hs b/System/Directory.hs
    index 1e44248..cfe7cd9 100644
    a b import System.FilePath 
    8585import System.IO
    8686import System.IO.Error
    8787import Control.Monad           ( when, unless )
    88 import Control.Exception.Base
     88import Control.Exception.Base as E
    8989
    9090#ifdef __NHC__
    9191import Directory -- hiding ( getDirectoryContents
    import qualified System.Win32 as Win32 
    127127import qualified System.Posix as Posix
    128128#endif
    129129
    130 #if __GLASGOW_HASKELL__ < 703
     130#if __GLASGOW_HASKELL__ == 702
     131-- fileSystemEncoding exists only in base-4.4
    131132getFileSystemEncoding :: IO TextEncoding
    132133getFileSystemEncoding = return fileSystemEncoding
    133134#endif
    134135
     136#if __GLASGOW_HASKELL__ < 702
     137-- just like in base >= 4.4
     138catchIOError :: IO a -> (IOError -> IO a) -> IO a
     139catchIOError = E.catch
     140#endif
     141
    135142#endif /* __GLASGOW_HASKELL__ */
    136143
    137144{- $intro
    createDirectoryIfMissing create_parents path0 
    392399
    393400    createDir :: FilePath -> (IOException -> IO ()) -> IO ()
    394401    createDir dir notExistHandler = do
    395       r <- try $ createDirectory dir
     402      r <- E.try $ createDirectory dir
    396403      case (r :: Either IOException ()) of
    397404        Right ()                   -> return ()
    398405        Left  e
    createDirectoryIfMissing create_parents path0 
    416423                 then return ()
    417424                 else throw e
    418425#endif
    419               ) `catch` ((\_ -> return ()) :: IOException -> IO ())
     426              ) `E.catch` ((\_ -> return ()) :: IOException -> IO ())
    420427          | otherwise              -> throw e
    421428#endif  /* !__NHC__ */
    422429
    removeDirectoryRecursive startLoc = do 
    482489  removeDirectory startLoc
    483490  where
    484491    rm :: FilePath -> IO ()
    485     rm f = do temp <- try (removeFile f)
     492    rm f = do temp <- E.try (removeFile f)
    486493              case temp of
    487494                Left e  -> do isDir <- doesDirectoryExist f
    488495                              -- If f is not a directory, re-throw the error
    doesDirectoryExist name = 
    957964   (do stat <- Posix.getFileStatus name
    958965       return (Posix.isDirectory stat))
    959966#endif
    960    `catch` ((\ _ -> return False) :: IOException -> IO Bool)
     967   `E.catch` ((\ _ -> return False) :: IOException -> IO Bool)
    961968
    962969{- |The operation 'doesFileExist' returns 'True'
    963970if the argument file exists and is not a directory, and 'False' otherwise.
    doesFileExist name = 
    971978   (do stat <- Posix.getFileStatus name
    972979       return (not (Posix.isDirectory stat)))
    973980#endif
    974    `catch` ((\ _ -> return False) :: IOException -> IO Bool)
     981   `E.catch` ((\ _ -> return False) :: IOException -> IO Bool)
    975982
    976983{- |The 'getModificationTime' operation returns the
    977984clock time at which the file or directory was last modified.
    getHomeDirectory :: IO FilePath 
    10711078getHomeDirectory =
    10721079  modifyIOError ((`ioeSetLocation` "getHomeDirectory")) $ do
    10731080#if defined(mingw32_HOST_OS)
    1074     r <- try $ Win32.sHGetFolderPath nullPtr Win32.cSIDL_PROFILE nullPtr 0
     1081    r <- E.try $ Win32.sHGetFolderPath nullPtr Win32.cSIDL_PROFILE nullPtr 0
    10751082    case (r :: Either IOException String) of
    10761083      Right s -> return s
    10771084      Left  _ -> do
    1078         r1 <- try $ Win32.sHGetFolderPath nullPtr Win32.cSIDL_WINDOWS nullPtr 0
     1085        r1 <- E.try $ Win32.sHGetFolderPath nullPtr Win32.cSIDL_WINDOWS nullPtr 0
    10791086        case r1 of
    10801087          Right s -> return s
    10811088          Left  e -> ioError (e :: IOException)