update unicode FilePath handling

Based on http://hackage.haskell.org/trac/ghc/ticket/3307 ,
whether FilePath contains decoded unicode varies by OS.
So, add a configure check for it.

Also, renamed showFile to filePathToString
This commit is contained in:
Joey Hess 2011-02-11 15:37:37 -04:00
parent 285fb2bb08
commit 5a50a7cf13
11 changed files with 34 additions and 16 deletions

View file

@ -193,14 +193,14 @@ checkKeyNumCopies key file numcopies = do
missingNote :: String -> Int -> Int -> String -> String missingNote :: String -> Int -> Int -> String -> String
missingNote file 0 _ [] = missingNote file 0 _ [] =
"** No known copies of " ++ showFile file ++ " exist!" "** No known copies of " ++ filePathToString file ++ " exist!"
missingNote file 0 _ untrusted = missingNote file 0 _ untrusted =
"Only these untrusted locations may have copies of " ++ showFile file ++ "Only these untrusted locations may have copies of " ++ filePathToString file ++
"\n" ++ untrusted ++ "\n" ++ untrusted ++
"Back it up to trusted locations with git-annex copy." "Back it up to trusted locations with git-annex copy."
missingNote file present needed [] = missingNote file present needed [] =
"Only " ++ show present ++ " of " ++ show needed ++ "Only " ++ show present ++ " of " ++ show needed ++
" trustworthy copies of " ++ showFile file ++ " exist." ++ " trustworthy copies of " ++ filePathToString file ++ " exist." ++
"\nBack it up with git-annex copy." "\nBack it up with git-annex copy."
missingNote file present needed untrusted = missingNote file present needed untrusted =
missingNote file present needed [] ++ missingNote file present needed [] ++

View file

@ -58,5 +58,5 @@ checkKeySHA1 key = do
then return True then return True
else do else do
dest <- moveBad key dest <- moveBad key
warning $ "Bad file content; moved to " ++ showFile dest warning $ "Bad file content; moved to " ++ filePathToString dest
return False return False

View file

@ -67,5 +67,5 @@ checkKeySize key = do
then return True then return True
else do else do
dest <- moveBad key dest <- moveBad key
warning $ "Bad file size; moved to " ++ showFile dest warning $ "Bad file size; moved to " ++ filePathToString dest
return False return False

View file

@ -25,5 +25,5 @@ seek = [withFilesInGit start]
start :: CommandStartString start :: CommandStartString
start file = isAnnexed file $ \(key, _) -> do start file = isAnnexed file $ \(key, _) -> do
exists <- inAnnex key exists <- inAnnex key
when exists $ liftIO $ putStrLn $ showFile file when exists $ liftIO $ putStrLn $ filePathToString file
return Nothing return Nothing

View file

@ -33,7 +33,7 @@ perform pair@(file, _) = do
ok <- doCommand $ Command.Add.start pair ok <- doCommand $ Command.Add.start pair
if ok if ok
then return $ Just $ cleanup file then return $ Just $ cleanup file
else error $ "failed to add " ++ showFile file ++ "; canceling commit" else error $ "failed to add " ++ filePathToString file ++ "; canceling commit"
cleanup :: FilePath -> CommandCleanup cleanup :: FilePath -> CommandCleanup
cleanup file = do cleanup file = do

View file

@ -68,7 +68,7 @@ checkUnused = do
dropmsg = ["(To remove unwanted data: git-annex dropunused NUMBER)"] dropmsg = ["(To remove unwanted data: git-annex dropunused NUMBER)"]
table l = [" NUMBER KEY"] ++ map cols l table l = [" NUMBER KEY"] ++ map cols l
cols (n,k) = " " ++ pad 6 (show n) ++ " " ++ (showFile . show) k cols (n,k) = " " ++ pad 6 (show n) ++ " " ++ (filePathToString . show) k
pad n s = s ++ replicate (n - length s) ' ' pad n s = s ++ replicate (n - length s) ' '
number :: Int -> [a] -> [(Int, a)] number :: Int -> [a] -> [(Int, a)]

View file

@ -50,7 +50,7 @@ calcGitLink file key = do
cwd <- liftIO $ getCurrentDirectory cwd <- liftIO $ getCurrentDirectory
let absfile = case absNormPath cwd file of let absfile = case absNormPath cwd file of
Just f -> f Just f -> f
Nothing -> error $ "unable to normalize " ++ showFile file Nothing -> error $ "unable to normalize " ++ filePathToString file
return $ relPathDirToDir (parentDir absfile) (Git.workTree g) ++ return $ relPathDirToDir (parentDir absfile) (Git.workTree g) ++
annexLocation key annexLocation key

View file

@ -11,10 +11,11 @@ import Control.Monad.State (liftIO)
import System.IO import System.IO
import Control.Monad (unless) import Control.Monad (unless)
import Data.String.Utils import Data.String.Utils
import Codec.Binary.UTF8.String as UTF8 import qualified Codec.Binary.UTF8.String as UTF8
import Types import Types
import qualified Annex import qualified Annex
import SysConfig
verbose :: Annex () -> Annex () verbose :: Annex () -> Annex ()
verbose a = do verbose a = do
@ -26,7 +27,7 @@ showSideAction s = verbose $ liftIO $ putStrLn $ "(" ++ s ++ ")"
showStart :: String -> String -> Annex () showStart :: String -> String -> Annex ()
showStart command file = verbose $ do showStart command file = verbose $ do
liftIO $ putStr $ command ++ " " ++ showFile file ++ " " liftIO $ putStr $ command ++ " " ++ filePathToString file ++ " "
liftIO $ hFlush stdout liftIO $ hFlush stdout
showNote :: String -> Annex () showNote :: String -> Annex ()
@ -58,7 +59,8 @@ warning w = do
indent :: String -> String indent :: String -> String
indent s = join "\n" $ map (\l -> " " ++ l) $ lines s indent s = join "\n" $ map (\l -> " " ++ l) $ lines s
{- Prepares a filename for display. This is needed because strings are {- Prepares a filename for display. This is needed because on many
- internally represented in git-annex is non-decoded form. -} - platforms (eg, unix), FilePaths are internally stored in
showFile :: FilePath -> String - non-decoded form. -}
showFile = decodeString filePathToString :: FilePath -> String
filePathToString = if unicodefilepath then id else UTF8.decodeString

View file

@ -1,6 +1,7 @@
{- Checks system configuration and generates SysConfig.hs. -} {- Checks system configuration and generates SysConfig.hs. -}
import System.Directory import System.Directory
import Data.List
import TestConfig import TestConfig
@ -13,6 +14,7 @@ tests = [
, TestCase "sha1sum" $ requireCmd "sha1sum" "sha1sum </dev/null" , TestCase "sha1sum" $ requireCmd "sha1sum" "sha1sum </dev/null"
, TestCase "xargs -0" $ requireCmd "xargs_0" "xargs -0 </dev/null" , TestCase "xargs -0" $ requireCmd "xargs_0" "xargs -0 </dev/null"
, TestCase "rsync" $ requireCmd "rsync" "rsync --version >/dev/null" , TestCase "rsync" $ requireCmd "rsync" "rsync --version >/dev/null"
, TestCase "unicode FilePath support" $ unicodeFilePath
] ]
tmpDir :: String tmpDir :: String
@ -27,6 +29,19 @@ testCp k option = TestCase cmd $ testCmd k run
cmd = "cp " ++ option cmd = "cp " ++ option
run = cmd ++ " " ++ testFile ++ " " ++ testFile ++ ".new" run = cmd ++ " " ++ testFile ++ " " ++ testFile ++ ".new"
{- Checks if FilePaths contain decoded unicode, or not. The testdata
- directory contains a "unicode-test-ü" file; try to find the file,
- and see if the "ü" is encoded correctly.
-
- Note that the file is shipped with git-annex, rather than created,
- to avoid other potential unicode issues.
-}
unicodeFilePath :: Test
unicodeFilePath = do
fs <- getDirectoryContents "testdata"
let file = head $ filter (isInfixOf "unicode-test") fs
return $ Config "unicodefilepath" (BoolConfig $ isInfixOf "ü" file)
setup :: IO () setup :: IO ()
setup = do setup = do
createDirectoryIfMissing True tmpDir createDirectoryIfMissing True tmpDir

View file

@ -46,7 +46,7 @@ It looks like the common latin1-to-UTF8 encoding. Functionality other than otupu
> user's configured encoding), and allow haskell's output encoding to then > user's configured encoding), and allow haskell's output encoding to then
> encode it according to the user's locale configuration. > encode it according to the user's locale configuration.
> > This is now [[implemented|done]]. I'm not very happy that I have to watch > > This is now [[implemented|done]]. I'm not very happy that I have to watch
> > out for any place that a filename is output and call `showFile` > > out for any place that a filename is output and call `filePathToString`
> > on it, but there are really not too many such places in git-annex. > > on it, but there are really not too many such places in git-annex.
> > > >
> > Note that this only affects filenames apparently. > > Note that this only affects filenames apparently.

1
testdata/unicode-test-ö vendored Normal file
View file

@ -0,0 +1 @@
hi