From cd890acc6fbb2b228f0903f0cea313fde02c026f Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 13 Jun 2017 15:26:47 +0300 Subject: refactoring --- src/WindowsEnv/Registry.hs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/WindowsEnv/Registry.hs') diff --git a/src/WindowsEnv/Registry.hs b/src/WindowsEnv/Registry.hs index 73606d9..3121d9d 100644 --- a/src/WindowsEnv/Registry.hs +++ b/src/WindowsEnv/Registry.hs @@ -50,7 +50,7 @@ import Foreign.ForeignPtr (withForeignPtr) import Foreign.Marshal.Alloc (alloca, allocaBytes) import Foreign.Marshal.Array (peekArray, pokeArray) import Foreign.Storable (peek, poke) -import System.IO.Error (catchIOError) +import System.IO.Error (tryIOError) import qualified System.Win32.Types as WinAPI import qualified System.Win32.Registry as WinAPI @@ -63,16 +63,12 @@ closeKey :: Handle -> IO () closeKey = WinAPI.regCloseKey openKey :: IsKeyPath a => a -> IO (Either IOError Handle) -openKey keyPath = catchIOError doOpenKey wrapError - where - doOpenKey = Right <$> openKeyUnsafe keyPath - wrapError = return . Left +openKey keyPath = tryIOError $ openKeyUnsafe keyPath withHandle :: IsKeyPath a => a -> (Handle -> IO b) -> ExceptT IOError IO b -withHandle keyPath f = ExceptT $ catchIOError doWithHandle wrapError +withHandle keyPath f = ExceptT $ tryIOError doWithHandle where - doWithHandle = Right <$> bracket (openKeyUnsafe keyPath) closeKey f - wrapError = return . Left + doWithHandle = bracket (openKeyUnsafe keyPath) closeKey f data RootKey = CurrentUser | LocalMachine -- cgit v1.2.3