diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-21 20:33:21 +0200 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-21 20:33:21 +0200 |
| commit | 671d401b7b3d5a3d0733a84fbdebca355bd43176 (patch) | |
| tree | 0be4ca68dfda4badf7ccc15365587714df011263 /adjmix/Adjmix.hs | |
| parent | 1b7643048e11da84216cd4e23d894a0767ee3061 (diff) | |
| download | trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar.gz trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar.bz2 trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.tar.xz trivmix-671d401b7b3d5a3d0733a84fbdebca355bd43176.zip | |
locking in adjmix
Diffstat (limited to 'adjmix/Adjmix.hs')
| -rw-r--r-- | adjmix/Adjmix.hs | 7 |
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 @@ | |||
| 3 | import Options.Applicative | 3 | import Options.Applicative |
| 4 | 4 | ||
| 5 | import System.FilePath | 5 | import System.FilePath |
| 6 | import System.FileLock | ||
| 6 | 7 | ||
| 7 | import Data.Char | 8 | import 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 | ||
| 61 | adjmix :: Options -> IO () | 66 | adjmix :: Options -> IO () |
| 62 | adjmix Options{..} = do | 67 | adjmix 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 |
