diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-09 23:11:46 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2015-06-09 23:11:46 +0200 |
commit | 0948d8545d916b13784b4cb6463352c060d839a2 (patch) | |
tree | fb4a61feb1b842eeb4b139ae7927530595b11d04 | |
parent | 64575e9bd793d8a77f587f44eb695b2065fe86ed (diff) | |
download | trivmix-0948d8545d916b13784b4cb6463352c060d839a2.tar trivmix-0948d8545d916b13784b4cb6463352c060d839a2.tar.gz trivmix-0948d8545d916b13784b4cb6463352c060d839a2.tar.bz2 trivmix-0948d8545d916b13784b4cb6463352c060d839a2.tar.xz trivmix-0948d8545d916b13784b4cb6463352c060d839a2.zip |
more verbose output
-rw-r--r-- | src/Trivmix.hs | 33 | ||||
-rw-r--r-- | trivmix.cabal | 2 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/Trivmix.hs b/src/Trivmix.hs index 7a786f3..4af2165 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs | |||
@@ -156,10 +156,11 @@ onStateFile file initial action = do | |||
156 | let directory = takeDirectory file | 156 | let directory = takeDirectory file |
157 | dirExists <- doesDirectoryExist directory | 157 | dirExists <- doesDirectoryExist directory |
158 | exists <- doesFileExist file | 158 | exists <- doesFileExist file |
159 | createDirectoryIfMissing True directory | ||
160 | let acquireFile = case exists of | 159 | let acquireFile = case exists of |
161 | True -> return () | 160 | True -> return () |
162 | False -> createFile file fileMode >>= closeFd >> writeFile file initial | 161 | False -> do |
162 | putStrLn $ "Creating ‘" ++ file ++ "’ (file)" | ||
163 | createFile file fileMode >>= closeFd >> writeFile file initial | ||
163 | fileMode = foldl unionFileModes nullFileMode [ ownerReadMode | 164 | fileMode = foldl unionFileModes nullFileMode [ ownerReadMode |
164 | , ownerWriteMode | 165 | , ownerWriteMode |
165 | , groupReadMode | 166 | , groupReadMode |
@@ -167,20 +168,34 @@ onStateFile file initial action = do | |||
167 | ] | 168 | ] |
168 | releaseFile = case exists of | 169 | releaseFile = case exists of |
169 | True -> return () | 170 | True -> return () |
170 | False -> removeFile file | 171 | False -> do |
172 | putStrLn $ "Removing ‘" ++ file ++ "’ (file)" | ||
173 | removeFile file | ||
174 | acquireDir = case dirExists of | ||
175 | True -> return () | ||
176 | False -> do | ||
177 | putStrLn $ "Creating ‘" ++ directory ++ "’ (dir" | ||
178 | createDirectoryIfMissing True directory | ||
171 | releaseDir = case dirExists of | 179 | releaseDir = case dirExists of |
172 | True -> return () | 180 | True -> return () |
173 | False -> removeDirectory directory | 181 | False -> do |
174 | acquire = acquireFile | 182 | putStrLn $ "Removing ‘" ++ directory ++ "’ (dir)" |
183 | removeDirectory directory | ||
184 | acquire = acquireDir >> acquireFile | ||
175 | release = releaseFile >> releaseDir | 185 | release = releaseFile >> releaseDir |
176 | bracket_ acquire release action | 186 | bracket_ acquire release action |
177 | 187 | ||
178 | readLevel :: Chan Level -> MVar Level -> FilePath -> IO () | 188 | readLevel :: Chan Level -> MVar Level -> FilePath -> IO () |
179 | readLevel levelChan current file = catch action handler | 189 | readLevel levelChan current file = catch action handler |
180 | where | 190 | where |
181 | action = readFile file >>= readIO . stripSpace >>= writeChan levelChan | 191 | action = do |
192 | level <- readFile file >>= readIO . stripSpace | ||
193 | writeChan levelChan level | ||
194 | putStrLn $ "Detected new level: " ++ (show level) | ||
182 | handler e = if isUserError e | 195 | handler e = if isUserError e |
183 | then readMVar current >>= writeLevel file | 196 | then do |
197 | putStrLn $ "Could not parse new level from ‘" ++ file ++ "’ - overwriting." | ||
198 | readMVar current >>= writeLevel file | ||
184 | else throw e | 199 | else throw e |
185 | stripSpace = reverse . stripSpace' . reverse . stripSpace' | 200 | stripSpace = reverse . stripSpace' . reverse . stripSpace' |
186 | stripSpace' [] = [] | 201 | stripSpace' [] = [] |
@@ -189,4 +204,6 @@ readLevel levelChan current file = catch action handler | |||
189 | else l | 204 | else l |
190 | 205 | ||
191 | writeLevel :: FilePath -> Level -> IO () | 206 | writeLevel :: FilePath -> Level -> IO () |
192 | writeLevel file level = writeFile file (show level ++ "\n") | 207 | writeLevel file level = do |
208 | putStrLn $ "Writing out level ‘" ++ (show level) ++ "’ to ‘" ++ file ++ "’" | ||
209 | writeFile file (show level ++ "\n") | ||
diff --git a/trivmix.cabal b/trivmix.cabal index 596a93d..692a90a 100644 --- a/trivmix.cabal +++ b/trivmix.cabal | |||
@@ -2,7 +2,7 @@ | |||
2 | -- documentation, see http://haskell.org/cabal/users-guide/ | 2 | -- documentation, see http://haskell.org/cabal/users-guide/ |
3 | 3 | ||
4 | name: trivmix | 4 | name: trivmix |
5 | version: 2.2.1 | 5 | version: 2.2.2 |
6 | -- synopsis: | 6 | -- synopsis: |
7 | -- description: | 7 | -- description: |
8 | license: PublicDomain | 8 | license: PublicDomain |