aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apps/AddPath.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/AddPath.hs
parentREADME update (diff)
downloadwindows-env-0d8b7efe4d74aa59513790da795ac4fde21be79b.tar.gz
windows-env-0d8b7efe4d74aa59513790da795ac4fde21be79b.zip
safer registry access routines
+ use patched Win32.
Diffstat (limited to 'apps/AddPath.hs')
-rw-r--r--apps/AddPath.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/apps/AddPath.hs b/apps/AddPath.hs
index 5fba7ce..9f9a5b1 100644
--- a/apps/AddPath.hs
+++ b/apps/AddPath.hs
@@ -6,9 +6,9 @@
module Main (main) where
-import Control.Monad (void, when)
-import Data.List (union)
-import Data.Maybe (fromMaybe)
+import Control.Monad (void, when)
+import Data.List (union)
+import System.IO.Error (ioError, isDoesNotExistError)
import Options.Applicative
import qualified Windows.Environment as Env
@@ -52,8 +52,8 @@ main = execParser parser >>= addPath
addPath :: Options -> IO ()
addPath options = do
- oldValue <- Env.query profile varName
- let oldPaths = Env.pathSplit $ fromMaybe "" oldValue
+ oldValue <- Env.query profile varName >>= emptyIfNotFound
+ let oldPaths = Env.pathSplit oldValue
let newPaths = oldPaths `union` pathsToAdd
when (length oldPaths /= length newPaths) $ do
let newValue = Env.pathJoin newPaths
@@ -72,3 +72,8 @@ addPath options = do
| otherwise = Env.CurrentUser
skipPrompt = optYes options
+
+ emptyIfNotFound (Left e)
+ | isDoesNotExistError e = return ""
+ | otherwise = ioError e
+ emptyIfNotFound (Right s) = return s