aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/RemovePath.hs
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-11-10 15:18:30 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-11-10 15:18:30 +0300
commit0d8b7efe4d74aa59513790da795ac4fde21be79b (patch)
tree8a60217b6b8ac2c23e90dcb71df457c03d3c5acd /apps/RemovePath.hs
parentREADME update (diff)
downloadwindows-env-0d8b7efe4d74aa59513790da795ac4fde21be79b.tar.gz
windows-env-0d8b7efe4d74aa59513790da795ac4fde21be79b.zip
safer registry access routines
+ use patched Win32.
Diffstat (limited to 'apps/RemovePath.hs')
-rw-r--r--apps/RemovePath.hs34
1 files changed, 19 insertions, 15 deletions
diff --git a/apps/RemovePath.hs b/apps/RemovePath.hs
index 1c8ee51..2956517 100644
--- a/apps/RemovePath.hs
+++ b/apps/RemovePath.hs
@@ -6,9 +6,9 @@
module Main (main) where
-import Control.Monad (void, when)
-import Data.List ((\\))
-import Data.Maybe (fromJust, isJust)
+import Control.Monad (void, when)
+import Data.List ((\\))
+import System.IO.Error (ioError, isDoesNotExistError)
import Options.Applicative
import qualified Windows.Environment as Env
@@ -63,15 +63,19 @@ removePath options = do
skipPrompt = optYes options
- removePathFrom profile = do
- oldValue <- Env.query profile varName
- when (isJust oldValue) $ do
- let oldPaths = Env.pathSplit $ fromJust oldValue
- let newPaths = oldPaths \\ pathsToRemove
- when (length oldPaths /= length newPaths) $ do
- let newValue = Env.pathJoin newPaths
- let promptAnd = if skipPrompt
- then withoutPrompt
- else withPrompt $ engraveMessage profile varName oldValue newValue
- let engrave = Env.engrave profile varName newValue
- void $ promptAnd engrave
+ removePathFrom profile = Env.query profile varName >>= either ignoreMissing (doRemovePathFrom profile)
+
+ ignoreMissing e
+ | isDoesNotExistError e = return ()
+ | otherwise = ioError e
+
+ doRemovePathFrom profile oldValue = do
+ let oldPaths = Env.pathSplit oldValue
+ let newPaths = oldPaths \\ pathsToRemove
+ when (length oldPaths /= length newPaths) $ do
+ let newValue = Env.pathJoin newPaths
+ let promptAnd = if skipPrompt
+ then withoutPrompt
+ else withPrompt $ engraveMessage profile varName oldValue newValue
+ let engrave = Env.engrave profile varName newValue
+ void $ promptAnd engrave