diff options
author | Joey Hess <joey@kitenet.net> | 2013-11-20 13:42:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-11-20 13:42:25 -0400 |
commit | 655fa61307f580c400072be12f9e5f3be3cef4a8 (patch) | |
tree | c8b0f6cc89a92897935558017b48b877503263ba | |
parent | 24c0b0039d37089169ee12ae996505c1e52fbd62 (diff) | |
download | git-repair-655fa61307f580c400072be12f9e5f3be3cef4a8.tar.gz |
merge from git-annex
-rw-r--r-- | Utility/Misc.hs | 10 | ||||
-rw-r--r-- | Utility/Tmp.hs | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Utility/Misc.hs b/Utility/Misc.hs index 4b0e9a1..68199c8 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -21,6 +21,9 @@ import System.Posix.Process (getAnyProcessStatus) import Utility.Exception #endif +import Utility.FileSystemEncoding +import Utility.Monad + {- A version of hgetContents that is not lazy. Ensures file is - all read before it gets closed. -} hGetContentsStrict :: Handle -> IO String @@ -30,6 +33,13 @@ hGetContentsStrict = hGetContents >=> \s -> length s `seq` return s readFileStrict :: FilePath -> IO String readFileStrict = readFile >=> \s -> length s `seq` return s +{- Reads a file strictly, and using the FileSystemEncofing, so it will + - never crash on a badly encoded file. -} +readFileStrictAnyEncoding :: FilePath -> IO String +readFileStrictAnyEncoding f = withFile f ReadMode $ \h -> do + fileEncoding h + hClose h `after` hGetContentsStrict h + {- Like break, but the item matching the condition is not included - in the second result list. - diff --git a/Utility/Tmp.hs b/Utility/Tmp.hs index 186cd12..3770654 100644 --- a/Utility/Tmp.hs +++ b/Utility/Tmp.hs @@ -62,7 +62,7 @@ withTmpDirIn :: FilePath -> Template -> (FilePath -> IO a) -> IO a withTmpDirIn tmpdir template = bracket create remove where remove d = whenM (doesDirectoryExist d) $ - removeDirectoryRecursive d + return () -- removeDirectoryRecursive d create = do createDirectoryIfMissing True tmpdir makenewdir (tmpdir </> template) (0 :: Int) |