aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-06-12 03:07:33 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-06-12 03:07:33 +0300
commit94cf0225bf29b1f5d35d978cb5483983589c0ba0 (patch)
tree3d7aeacb220b9aba531af2a841ca7e45b8489914
parentsetenv: detect expandable values (diff)
downloadwindows-env-94cf0225bf29b1f5d35d978cb5483983589c0ba0.tar.gz
windows-env-94cf0225bf29b1f5d35d978cb5483983589c0ba0.zip
delpath: don't do anything if variable is missing
Diffstat (limited to '')
-rw-r--r--app/RemovePath.hs40
1 files changed, 18 insertions, 22 deletions
diff --git a/app/RemovePath.hs b/app/RemovePath.hs
index 7157100..a8bf56d 100644
--- a/app/RemovePath.hs
+++ b/app/RemovePath.hs
@@ -57,34 +57,30 @@ removePath options = runExceptT doRemovePath >>= either ioError return
where
varName = optName options
pathsToRemove = optPaths options
-
forAllUsers = optGlobal options
-
skipPrompt = optYes options
- emptyIfMissing e
- | isDoesNotExistError e = defaultValue
+ ignoreMissing e
+ | isDoesNotExistError e = return ()
| otherwise = throwE e
- defaultValue = do
- expandedPaths <- mapM WindowsEnv.expand pathsToRemove
- if pathsToRemove == expandedPaths
- then return $ WindowsEnv.Value False ""
- else return $ WindowsEnv.Value True ""
-
doRemovePath = do
- removePathFrom WindowsEnv.CurrentUser
+ removePathFrom WindowsEnv.CurrentUser `catchE` ignoreMissing
when forAllUsers $
- removePathFrom WindowsEnv.AllUsers
+ removePathFrom WindowsEnv.AllUsers `catchE` ignoreMissing
removePathFrom profile = do
- oldValue <- WindowsEnv.query profile varName `catchE` emptyIfMissing
- let oldPaths = WindowsEnv.pathSplit $ show oldValue
- let newPaths = filter (flip notElem pathsToRemove) oldPaths
- when (length oldPaths /= length newPaths) $ do
- let newValue = WindowsEnv.Value (WindowsEnv.valueExpandable oldValue) (WindowsEnv.pathJoin newPaths)
- let promptAnd = if skipPrompt
- then withoutPrompt
- else withPrompt $ oldNewMessage profile varName oldValue newValue
- let engrave = WindowsEnv.engrave profile varName newValue
- void $ promptAnd engrave
+ oldValue <- WindowsEnv.query profile varName
+ let expandable = WindowsEnv.valueExpandable oldValue
+ let split = WindowsEnv.pathSplit $ WindowsEnv.valueString oldValue
+ let remaining = filter (flip notElem pathsToRemove) split
+ when (length split /= length remaining) $ do
+ let newValue = WindowsEnv.Value expandable (WindowsEnv.pathJoin remaining)
+ promptAndEngrave profile oldValue newValue
+
+ promptAndEngrave profile oldValue newValue = do
+ let promptAnd = if skipPrompt
+ then withoutPrompt
+ else withPrompt $ oldNewMessage profile varName oldValue newValue
+ let engrave = WindowsEnv.engrave profile varName newValue
+ void $ promptAnd engrave