diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-09-14 21:51:15 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-09-14 21:51:15 -0400 |
| commit | 6957710b8d2f178efdee336131c3935aebc0b76f (patch) | |
| tree | 90a57d79a0a90e000cea7161fbe0af2c4f4cc69e /src/Propellor/PrivData.hs | |
| parent | 9b715f72c2eb7dec71e0392a2363474f23c1e761 (diff) | |
| parent | 0d93f4f12c4c7d0a37dc2e6f792ce0f9dde793db (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/PrivData.hs')
| -rw-r--r-- | src/Propellor/PrivData.hs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index b7932518..a28fb195 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -31,6 +31,7 @@ import Control.Monad.IfElse import "mtl" Control.Monad.Reader import qualified Data.Map as M import qualified Data.Set as S +import qualified Data.ByteString.Lazy as L import Propellor.Types import Propellor.Types.PrivData @@ -48,6 +49,7 @@ import Utility.Misc import Utility.FileMode import Utility.Env import Utility.Table +import Utility.FileSystemEncoding -- | Allows a Property to access the value of a specific PrivDataField, -- for use in a specific Context or HostContext. @@ -149,6 +151,7 @@ getPrivData field context m = do setPrivData :: PrivDataField -> Context -> IO () setPrivData field context = do putStrLn "Enter private data on stdin; ctrl-D when done:" + fileEncoding stdin setPrivDataTo field context . PrivData =<< hGetContentsStrict stdin unsetPrivData :: PrivDataField -> Context -> IO () @@ -157,17 +160,17 @@ unsetPrivData field context = do putStrLn "Private data unset." dumpPrivData :: PrivDataField -> Context -> IO () -dumpPrivData field context = +dumpPrivData field context = do maybe (error "Requested privdata is not set.") - (mapM_ putStrLn . privDataLines) + (L.hPut stdout . privDataByteString) =<< (getPrivData field context <$> decryptPrivData) editPrivData :: PrivDataField -> Context -> IO () editPrivData field context = do v <- getPrivData field context <$> decryptPrivData - v' <- withTmpFile "propellorXXXX" $ \f h -> do - hClose h - maybe noop (writeFileProtected f . unlines . privDataLines) v + v' <- withTmpFile "propellorXXXX" $ \f th -> do + hClose th + maybe noop (\p -> writeFileProtected' f (`L.hPut` privDataByteString p)) v editor <- getEnvDefault "EDITOR" "vi" unlessM (boolSystem editor [File f]) $ error "Editor failed; aborting." |
