summaryrefslogtreecommitdiff
path: root/adjmix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-06-21 20:33:21 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-06-21 20:33:21 +0200
commit671d401b7b3d5a3d0733a84fbdebca355bd43176 (patch)
tree0be4ca68dfda4badf7ccc15365587714df011263 /adjmix
parent1b7643048e11da84216cd4e23d894a0767ee3061 (diff)
downloadtrivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar
trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar.gz
trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar.bz2
trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar.xz
trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.zip
locking in adjmix
Diffstat (limited to 'adjmix')
-rw-r--r--adjmix/Adjmix.hs7
1 files changed, 6 insertions, 1 deletions
diff --git a/adjmix/Adjmix.hs b/adjmix/Adjmix.hs
index 645ac6a..94416ac 100644
--- a/adjmix/Adjmix.hs
+++ b/adjmix/Adjmix.hs
@@ -3,6 +3,7 @@
3import Options.Applicative 3import Options.Applicative
4 4
5import System.FilePath 5import System.FilePath
6import System.FileLock
6 7
7import Data.Char 8import Data.Char
8 9
@@ -20,6 +21,7 @@ optionParser = Options
20 <> metavar "DIRECTORY" 21 <> metavar "DIRECTORY"
21 <> value "/dev/shm/mix" 22 <> value "/dev/shm/mix"
22 <> showDefault 23 <> showDefault
24 <> help "Base directory"
23 ) 25 )
24 <*> strOption ( long "target" 26 <*> strOption ( long "target"
25 <> short 't' 27 <> short 't'
@@ -35,16 +37,19 @@ optionParser = Options
35 <*> ( ( Set <$> option auto ( long "set" 37 <*> ( ( Set <$> option auto ( long "set"
36 <> short 'o' 38 <> short 'o'
37 <> metavar "LEVEL" 39 <> metavar "LEVEL"
40 <> help "Overwrite the current level"
38 ) 41 )
39 ) 42 )
40 <|> ( Add <$> option auto ( long "add" 43 <|> ( Add <$> option auto ( long "add"
41 <> short 'a' 44 <> short 'a'
42 <> metavar "LEVEL" 45 <> metavar "LEVEL"
46 <> help "Add to the current level"
43 ) 47 )
44 ) 48 )
45 <|> ( Sub <$> option auto ( long "sub" 49 <|> ( Sub <$> option auto ( long "sub"
46 <> short 's' 50 <> short 's'
47 <> metavar "LEVEL" 51 <> metavar "LEVEL"
52 <> help "Subtract from the current level"
48 ) 53 )
49 ) 54 )
50 ) 55 )
@@ -59,7 +64,7 @@ main = execParser opts >>= adjmix
59 ) 64 )
60 65
61adjmix :: Options -> IO () 66adjmix :: Options -> IO ()
62adjmix Options{..} = do 67adjmix Options{..} = withFileLock levelFile' Exclusive $ const $ do
63 oldLevel <- readFile levelFile' >>= readIO . stripSpace 68 oldLevel <- readFile levelFile' >>= readIO . stripSpace
64 let 69 let
65 newLevel = oldLevel `doAdjustment` adjustment 70 newLevel = oldLevel `doAdjustment` adjustment