fix ByteString conversion on windows
the encode' and decode' functions on Windows should not apply the filesystem encoding, which does not work there. Instead, convert to and from UTF-8. Also, avoid exporting encodeW8 and decodeW8. Both use the filesystem encoding, so won't work as expected on windows.
This commit is contained in:
		
					parent
					
						
							
								0246ecbe94
							
						
					
				
			
			
				commit
				
					
						322c542b5c
					
				
			
		
					 4 changed files with 23 additions and 8 deletions
				
			
		| 
						 | 
					@ -43,6 +43,7 @@ import Annex.LockPool
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Control.Concurrent.STM
 | 
					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
 | 
					{- 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
 | 
					 - 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
 | 
					{- Note that this looks at the true length of the path in bytes, as it will
 | 
				
			||||||
 - appear on disk. -}
 | 
					 - appear on disk. -}
 | 
				
			||||||
valid_unix_socket_path :: FilePath -> Bool
 | 
					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
 | 
					{- Parses the SSH port, and returns the other OpenSSH options. If
 | 
				
			||||||
 - several ports are found, the last one takes precedence. -}
 | 
					 - several ports are found, the last one takes precedence. -}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,6 +11,7 @@ import Annex.Common
 | 
				
			||||||
import Utility.Hash
 | 
					import Utility.Hash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import qualified Data.ByteString as S
 | 
					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.
 | 
					{- 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.
 | 
					 - 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.
 | 
						-- Avoid making keys longer than the length of a SHA256 checksum.
 | 
				
			||||||
	| bytelen > sha256len = encodeBS' $
 | 
						| bytelen > sha256len = encodeBS' $
 | 
				
			||||||
		truncateFilePath (sha256len - md5len - 1) s' ++ "-" ++ 
 | 
							truncateFilePath (sha256len - md5len - 1) s' ++ "-" ++ 
 | 
				
			||||||
			show (md5 (encodeBL s))
 | 
								show (md5 bl)
 | 
				
			||||||
	| otherwise = encodeBS' s'
 | 
						| otherwise = encodeBS' s'
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
	s' = preSanitizeKeyName s
 | 
						s' = preSanitizeKeyName s
 | 
				
			||||||
	bytelen = length (decodeW8 s')
 | 
						bl = encodeBL s
 | 
				
			||||||
 | 
						bytelen = fromIntegral $ L.length bl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sha256len = 64
 | 
						sha256len = 64
 | 
				
			||||||
	md5len = 32
 | 
						md5len = 32
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,10 +23,6 @@ module Utility.FileSystemEncoding (
 | 
				
			||||||
	encodeBL',
 | 
						encodeBL',
 | 
				
			||||||
	decodeBS',
 | 
						decodeBS',
 | 
				
			||||||
	encodeBS',
 | 
						encodeBS',
 | 
				
			||||||
	decodeW8,
 | 
					 | 
				
			||||||
	encodeW8,
 | 
					 | 
				
			||||||
	encodeW8NUL,
 | 
					 | 
				
			||||||
	decodeW8NUL,
 | 
					 | 
				
			||||||
	truncateFilePath,
 | 
						truncateFilePath,
 | 
				
			||||||
	s2w8,
 | 
						s2w8,
 | 
				
			||||||
	w82s,
 | 
						w82s,
 | 
				
			||||||
| 
						 | 
					@ -148,16 +144,32 @@ encodeBS = S8.fromString
 | 
				
			||||||
{- Faster version that assumes the string does not contain NUL;
 | 
					{- Faster version that assumes the string does not contain NUL;
 | 
				
			||||||
 - if it does it will be truncated before the NUL. -}
 | 
					 - if it does it will be truncated before the NUL. -}
 | 
				
			||||||
decodeBS' :: S.ByteString -> FilePath
 | 
					decodeBS' :: S.ByteString -> FilePath
 | 
				
			||||||
 | 
					#ifndef mingw32_HOST_OS
 | 
				
			||||||
decodeBS' = encodeW8 . S.unpack
 | 
					decodeBS' = encodeW8 . S.unpack
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					decodeBS' = S8.toString
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
encodeBS' :: FilePath -> S.ByteString
 | 
					encodeBS' :: FilePath -> S.ByteString
 | 
				
			||||||
 | 
					#ifndef mingw32_HOST_OS
 | 
				
			||||||
encodeBS' = S.pack . decodeW8
 | 
					encodeBS' = S.pack . decodeW8
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					encodeBS' = S8.fromString
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
decodeBL' :: L.ByteString -> FilePath
 | 
					decodeBL' :: L.ByteString -> FilePath
 | 
				
			||||||
 | 
					#ifndef mingw32_HOST_OS
 | 
				
			||||||
decodeBL' = encodeW8 . L.unpack
 | 
					decodeBL' = encodeW8 . L.unpack
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					decodeBL' = L8.toString
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
encodeBL' :: FilePath -> L.ByteString
 | 
					encodeBL' :: FilePath -> L.ByteString
 | 
				
			||||||
 | 
					#ifndef mingw32_HOST_OS
 | 
				
			||||||
encodeBL' = L.pack . decodeW8
 | 
					encodeBL' = L.pack . decodeW8
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					encodeBL' = L8.fromString
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{- Recent versions of the unix package have this alias; defined here
 | 
					{- Recent versions of the unix package have this alias; defined here
 | 
				
			||||||
 - for backwards compatibility. -}
 | 
					 - for backwards compatibility. -}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -258,7 +258,7 @@ commandMeter' progressparser oh meterupdate cmd params =
 | 
				
			||||||
				unless (quietMode oh) $ do
 | 
									unless (quietMode oh) $ do
 | 
				
			||||||
					S.hPut stdout b
 | 
										S.hPut stdout b
 | 
				
			||||||
					hFlush stdout
 | 
										hFlush stdout
 | 
				
			||||||
				let s = encodeW8 (S.unpack b)
 | 
									let s = decodeBS b
 | 
				
			||||||
				let (mbytes, buf') = progressparser (buf++s)
 | 
									let (mbytes, buf') = progressparser (buf++s)
 | 
				
			||||||
				case mbytes of
 | 
									case mbytes of
 | 
				
			||||||
					Nothing -> feedprogress prev buf' h
 | 
										Nothing -> feedprogress prev buf' h
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue