@@ -15,12 +15,10 @@ import System.Environment.Executable (getExecutablePath)
1515import System.Posix.Types (Fd)
1616import Data.Binary (encode)
1717import Data.Digest.Pure.MD5 (md5, MD5Digest)
18−import qualified Data.ByteString.Lazy as BSL (readFile)
19−import qualified Data.ByteString.Lazy.Char8 as BSLC (unpack)
18+import qualified Data.ByteString.Lazy as BSL (readFile, length)
2019import Control.Applicative ((<$>))
2120import Control.Monad (void)
2221import Control.Exception (catches, Handler(Handler))
23−import GHC.IO.Encoding (setForeignEncoding, char8)
2422
2523-- Azure
2624import Network.Azure.ServiceManagement
@@ -40,7 +38,6 @@ import qualified Network.SSH.Client.LibSSH2 as SSH
4038 , execCommands
4139 , scpSendFile
4240 , withChannel
43− , readAllChannel
4441 , Session
4542 )
4643import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
@@ -55,6 +52,10 @@ import qualified Network.SSH.Client.LibSSH2.Errors as SSH
5552 , NULL_POINTER
5653 , getLastError
5754 )
55+import qualified Network.SSH.Client.LibSSH2.ByteString.Lazy as SSHBS
56+ ( writeChannel
57+ , readAllChannel
58+ )
5859
5960-- CH
6061import Control.Distributed.Process
@@ -140,12 +141,9 @@ apiRunOnVM params vm port proc =
140141 putStrLn $ "Executing " ++ show exe
141142 r <- SSH.withChannel (SSH.openChannelSession s) id fd s $ \ch -> do
142143 SSH.retryIfNeeded fd s $ SSH.channelExecute ch exe
143− let enc = encode proc
144− putStrLn $ "Sending closure of size " ++ show (length (BSLC.unpack enc))
145− setForeignEncoding char8
146− SSH.writeChannel ch $ BSLC.unpack enc
144+ SSHBS.writeChannel fd ch (encode proc)
147145 SSH.channelSendEOF ch
148− SSH.readAllChannel fd ch
146+ SSHBS.readAllChannel fd ch
149147 print r
150148
151149-- | Check the MD5 hash of the executable on the remote machine
@@ -157,7 +155,7 @@ apiCheckMD5 params vm = do
157155 SSH.retryIfNeeded fd s $ SSH.channelExecute ch "md5sum -c --status"
158156 SSH.writeChannel ch $ show hash ++ " " ++ azureSshRemotePath params
159157 SSH.channelSendEOF ch
160− SSH.readAllChannel fd ch
158+ SSHBS.readAllChannel fd ch
161159 return (r == 0)
162160
163161withSSH2 :: AzureParameters -> VirtualMachine -> (Fd -> SSH.Session -> IO a) -> IO a