From 714fc992181311d88adb35cb59d766abbbc59811 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 11 Jun 2017 05:42:19 +0300 Subject: delenv: ignore missing variables --- src/WindowsEnv/Environment.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/WindowsEnv') diff --git a/src/WindowsEnv/Environment.hs b/src/WindowsEnv/Environment.hs index 9a42748..c194cbe 100644 --- a/src/WindowsEnv/Environment.hs +++ b/src/WindowsEnv/Environment.hs @@ -34,13 +34,13 @@ module WindowsEnv.Environment ) where import Control.Monad.Trans.Class (lift) -import Control.Monad.Trans.Except (ExceptT(..)) +import Control.Monad.Trans.Except (ExceptT(..), catchE, throwE) import Data.List (intercalate) import Data.List.Split (splitOn) import Foreign.Marshal.Alloc (allocaBytes) import Foreign.Storable (sizeOf) import System.Directory (doesDirectoryExist) -import System.IO.Error (catchIOError) +import System.IO.Error (catchIOError, isDoesNotExistError) import qualified System.Win32.Types as WinAPI import qualified WindowsEnv.Registry as Registry @@ -92,9 +92,13 @@ engrave profile name value = do wipe :: Profile -> VarName -> ExceptT IOError IO () wipe profile name = do - ret <- Registry.deleteValue (profileKeyPath profile) name + ret <- Registry.deleteValue (profileKeyPath profile) name `catchE` ignoreIfMissing lift notifyEnvironmentUpdate return ret + where + ignoreIfMissing e + | isDoesNotExistError e = return () + | otherwise = throwE e pathSep :: String pathSep = ";" -- cgit v1.2.3