diff options
| author | Joey Hess <joey@kitenet.net> | 2014-11-18 13:32:33 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-11-18 13:32:33 -0400 |
| commit | 9463963d855d6a19d423598f668b8627dd669a30 (patch) | |
| tree | 308ced2d1c9dc4255a73b6053ac54cd18337d103 /src/Propellor/Protocol.hs | |
| parent | fef2f77dafeb0378eaa1e733e00389edcf53c798 (diff) | |
reorg
Diffstat (limited to 'src/Propellor/Protocol.hs')
| -rw-r--r-- | src/Propellor/Protocol.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Propellor/Protocol.hs b/src/Propellor/Protocol.hs index a1643187..669f41b6 100644 --- a/src/Propellor/Protocol.hs +++ b/src/Propellor/Protocol.hs @@ -24,18 +24,19 @@ privDataMarker = "PRIVDATA " toMarked :: Marker -> String -> String toMarked marker = intercalate "\n" . map (marker ++) . lines +fromMarked :: Marker -> Marked -> Maybe String +fromMarked marker s + | marker `isPrefixOf` s = Just $ drop (length marker) s + | otherwise = Nothing + sendMarked :: Handle -> Marker -> String -> IO () sendMarked h marker s = do -- Prefix string with newline because sometimes a - -- incomplete line is output. + -- incomplete line has been output, and the marker needs to + -- come at the start of a line. hPutStrLn h ("\n" ++ toMarked marker s) hFlush h -fromMarked :: Marker -> Marked -> Maybe String -fromMarked marker s - | marker `isPrefixOf` s = Just $ drop (length marker) s - | otherwise = Nothing - getMarked :: Handle -> Marker -> IO (Maybe String) getMarked h marker = go =<< catchMaybeIO (hGetLine h) where |
