fix touch and statfs to work on any files in any locale

Use withCAString rather than withCString.

XXX Actually, this only works in non-unicode locales when presented with
unicode characters. Help?
This commit is contained in:
Joey Hess 2012-02-04 12:24:00 -04:00
parent 44b115e0b1
commit f1c7dc1212
3 changed files with 6 additions and 8 deletions

View file

@ -84,9 +84,9 @@ cleanup file key hascontent = do
-- file it points to
-- XXX Currently broken on non-utf8 locales when
-- dealing with utf-8 filenames.
--liftIO $ do
--mtime <- modificationTime <$> getFileStatus file
--touch file (TimeSpec mtime) False
liftIO $ do
mtime <- modificationTime <$> getFileStatus file
touch file (TimeSpec mtime) False
force <- Annex.getState Annex.force
if force

View file

@ -50,8 +50,6 @@ module Utility.StatFS ( FileSystemStats(..), getFileSystemStats ) where
import Foreign
import Foreign.C.Types
import Foreign.C.String
import Data.ByteString (useAsCString)
import Data.ByteString.Char8 (pack)
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
# include <sys/param.h>
@ -105,7 +103,7 @@ getFileSystemStats path =
return Nothing
#else
allocaBytes (#size struct statfs) $ \vfs ->
useAsCString (pack path) $ \cpath -> do
withCAString path $ \cpath -> do
res <- c_statfs cpath vfs
if res == -1 then return Nothing
else do

View file

@ -64,7 +64,7 @@ foreign import ccall "utimensat"
touchBoth file atime mtime follow =
allocaArray 2 $ \ptr ->
withCString file $ \f -> do
withCAString file $ \f -> do
pokeArray ptr [atime, mtime]
r <- c_utimensat at_fdcwd f ptr flags
when (r /= 0) $ throwErrno "touchBoth"
@ -101,7 +101,7 @@ foreign import ccall "lutimes"
touchBoth file atime mtime follow =
allocaArray 2 $ \ptr ->
withCString file $ \f -> do
withCAString file $ \f -> do
pokeArray ptr [atime, mtime]
r <- syscall f ptr
if (r /= 0)