From 37489c93248e5197f9b84b58c07680c9cb273189 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 12 Jun 2017 03:35:31 +0300 Subject: addpath: fix a sleep-deprived bug Yeah, so last night I added a Show instance to WindowsEnv.Value (ex-WindowsEnv.VarValue), which would simply call valueString (ex-varValueString). Then I replaced every valueString/varValueString with show. Then I decided that this Show instance was a mistake, and derived an instance instead. It obviously messed up all the show VarValue/Value calls. The lesson to learn is you should remove an instance first, fix all the call sites, and only then derive it. The disgusting part is that a few of the last commits are actually broken, which I hate. --- app/AddPath.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/AddPath.hs b/app/AddPath.hs index d141270..1152df6 100644 --- a/app/AddPath.hs +++ b/app/AddPath.hs @@ -63,14 +63,13 @@ addPath options = runExceptT doAddPath >>= either ioError return where varName = optName options pathsToAdd = nub $ optPaths options - forAllUsers = optGlobal options + skipPrompt = optYes options + profile | forAllUsers = WindowsEnv.AllUsers | otherwise = WindowsEnv.CurrentUser - skipPrompt = optYes options - prepend = optPrepend options mergePaths old new | prepend = new ++ old @@ -88,10 +87,13 @@ addPath options = runExceptT doAddPath >>= either ioError return doAddPath = do oldValue <- WindowsEnv.query profile varName `catchE` emptyIfMissing - let oldPaths = WindowsEnv.pathSplit $ show oldValue - let newPaths = pathsToAdd \\ oldPaths - unless (null newPaths) $ do - let newValue = WindowsEnv.Value (WindowsEnv.valueExpandable oldValue) $ WindowsEnv.pathJoin (mergePaths oldPaths newPaths) + let expandable = WindowsEnv.valueExpandable oldValue + let joined = WindowsEnv.valueString oldValue + let split = WindowsEnv.pathSplit joined + let missing = pathsToAdd \\ split + unless (null missing) $ do + let merged = mergePaths split missing + let newValue = WindowsEnv.Value expandable (WindowsEnv.pathJoin merged) promptAndEngrave oldValue newValue promptAndEngrave oldValue newValue = do -- cgit v1.2.3