diff options
-rw-r--r-- | Annex/Content/Direct.hs | 9 | ||||
-rw-r--r-- | Utility/Misc.hs | 7 |
2 files changed, 9 insertions, 7 deletions
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs index a5d71288b..35d2c9b8d 100644 --- a/Annex/Content/Direct.hs +++ b/Annex/Content/Direct.hs @@ -66,15 +66,10 @@ changeAssociatedFiles key transform = do let files' = transform files when (files /= files') $ do modifyContent mapping $ - liftIO $ viaTmp write mapping $ unlines files' + liftIO $ viaTmp writeFileAnyEncoding mapping $ + unlines files' top <- fromRepo Git.repoPath return $ map (top </>) files' - where - write file content = do - h <- openFile file WriteMode - fileEncoding h - hPutStr h content - hClose h {- Removes the list of associated files. -} removeAssociatedFiles :: Key -> Annex () diff --git a/Utility/Misc.hs b/Utility/Misc.hs index b93b772a9..20007adad 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -40,6 +40,13 @@ readFileStrictAnyEncoding f = withFile f ReadMode $ \h -> do fileEncoding h hClose h `after` hGetContentsStrict h +{- Writes a file, using the FileSystemEncoding so it will never crash + - on a badly encoded content string. -} +writeFileAnyEncoding :: FilePath -> String -> IO () +writeFileAnyEncoding f content = withFile f WriteMode $ \h -> do + fileEncoding h + hPutStr h content + {- Like break, but the item matching the condition is not included - in the second result list. - |