diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs index a4cb5013eb..9fea51a929 100644 --- a/Annex/Ssh.hs +++ b/Annex/Ssh.hs @@ -43,6 +43,7 @@ import Annex.LockPool #endif import Control.Concurrent.STM +import qualified Data.ByteString as S {- Some ssh commands are fed stdin on a pipe and so should be allowed to - consume it. But ssh commands that are not piped stdin should generally @@ -325,7 +326,7 @@ sizeof_sockaddr_un_sun_path = 100 {- Note that this looks at the true length of the path in bytes, as it will - appear on disk. -} valid_unix_socket_path :: FilePath -> Bool -valid_unix_socket_path f = length (decodeW8 f) < sizeof_sockaddr_un_sun_path +valid_unix_socket_path f = S.length (encodeBS f) < sizeof_sockaddr_un_sun_path {- Parses the SSH port, and returns the other OpenSSH options. If - several ports are found, the last one takes precedence. -} diff --git a/Backend/Utilities.hs b/Backend/Utilities.hs index bcb0c4bda4..0baaa476c9 100644 --- a/Backend/Utilities.hs +++ b/Backend/Utilities.hs @@ -11,6 +11,7 @@ import Annex.Common import Utility.Hash import qualified Data.ByteString as S +import qualified Data.ByteString.Lazy as L {- Generates a keyName from an input string. Takes care of sanitizing it. - If it's not too long, the full string is used as the keyName. @@ -21,11 +22,12 @@ genKeyName s -- Avoid making keys longer than the length of a SHA256 checksum. | bytelen > sha256len = encodeBS' $ truncateFilePath (sha256len - md5len - 1) s' ++ "-" ++ - show (md5 (encodeBL s)) + show (md5 bl) | otherwise = encodeBS' s' where s' = preSanitizeKeyName s - bytelen = length (decodeW8 s') + bl = encodeBL s + bytelen = fromIntegral $ L.length bl sha256len = 64 md5len = 32 diff --git a/Utility/FileSystemEncoding.hs b/Utility/FileSystemEncoding.hs index bb3738ed96..f9e98145a7 100644 --- a/Utility/FileSystemEncoding.hs +++ b/Utility/FileSystemEncoding.hs @@ -23,10 +23,6 @@ module Utility.FileSystemEncoding ( encodeBL', decodeBS', encodeBS', - decodeW8, - encodeW8, - encodeW8NUL, - decodeW8NUL, truncateFilePath, s2w8, w82s, @@ -148,16 +144,32 @@ encodeBS = S8.fromString {- Faster version that assumes the string does not contain NUL; - if it does it will be truncated before the NUL. -} decodeBS' :: S.ByteString -> FilePath +#ifndef mingw32_HOST_OS decodeBS' = encodeW8 . S.unpack +#else +decodeBS' = S8.toString +#endif encodeBS' :: FilePath -> S.ByteString +#ifndef mingw32_HOST_OS encodeBS' = S.pack . decodeW8 +#else +encodeBS' = S8.fromString +#endif decodeBL' :: L.ByteString -> FilePath +#ifndef mingw32_HOST_OS decodeBL' = encodeW8 . L.unpack +#else +decodeBL' = L8.toString +#endif encodeBL' :: FilePath -> L.ByteString +#ifndef mingw32_HOST_OS encodeBL' = L.pack . decodeW8 +#else +encodeBL' = L8.fromString +#endif {- Recent versions of the unix package have this alias; defined here - for backwards compatibility. -} diff --git a/Utility/Metered.hs b/Utility/Metered.hs index 53e253eccb..ec16e334c7 100644 --- a/Utility/Metered.hs +++ b/Utility/Metered.hs @@ -258,7 +258,7 @@ commandMeter' progressparser oh meterupdate cmd params = unless (quietMode oh) $ do S.hPut stdout b hFlush stdout - let s = encodeW8 (S.unpack b) + let s = decodeBS b let (mbytes, buf') = progressparser (buf++s) case mbytes of Nothing -> feedprogress prev buf' h