summaryrefslogtreecommitdiff
path: root/Annex/Content/Direct.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-01-18 12:26:45 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-01-18 12:26:45 -0400
commit8a90ce164c90aef0fd9b7e992bb36935e7a963c5 (patch)
tree4cbcf7a848e258c6798387367bd80d4f8710f432 /Annex/Content/Direct.hs
parent72445900116cfce9daa8841097096db3b64a3b16 (diff)
Avoid filename encoding errors when writing direct mode mappings.
Diffstat (limited to 'Annex/Content/Direct.hs')
-rw-r--r--Annex/Content/Direct.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/Annex/Content/Direct.hs b/Annex/Content/Direct.hs
index 822ae0608..889c27231 100644
--- a/Annex/Content/Direct.hs
+++ b/Annex/Content/Direct.hs
@@ -41,7 +41,10 @@ associatedFiles key = do
associatedFilesRelative :: Key -> Annex [FilePath]
associatedFilesRelative key = do
mapping <- inRepo $ gitAnnexMapping key
- liftIO $ catchDefaultIO [] $ lines <$> readFile mapping
+ liftIO $ catchDefaultIO [] $ do
+ h <- openFile mapping ReadMode
+ fileEncoding h
+ hClose h `after` (lines <$> hGetContents h)
{- Changes the associated files information for a key, applying a
- transformation to the list. Returns new associatedFiles value. -}
@@ -51,9 +54,15 @@ changeAssociatedFiles key transform = do
files <- associatedFilesRelative key
let files' = transform files
when (files /= files') $
- liftIO $ viaTmp writeFile mapping $ unlines files'
+ liftIO $ viaTmp write 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 an associated file. Returns new associatedFiles value. -}
removeAssociatedFile :: Key -> FilePath -> Annex [FilePath]