From 44bf67b7a2da75ef80e32d6409cc41a6ab8b6ffe Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 24 Dec 2016 15:14:05 -0400 Subject: GHC's fileSystemEncoding is used for all String IO, to avoid encoding-related crashes in eg, Propellor.Property.File. --- src/Propellor/CmdLine.hs | 2 ++ src/Propellor/Gpg.hs | 7 ++----- src/Propellor/PrivData.hs | 4 +--- src/Propellor/Property.hs | 2 +- src/Propellor/Property/Debootstrap.hs | 2 +- src/Propellor/Property/Gpg.hs | 2 -- src/Propellor/Shim.hs | 2 -- 7 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src/Propellor') diff --git a/src/Propellor/CmdLine.hs b/src/Propellor/CmdLine.hs index fc256109..c407fce8 100644 --- a/src/Propellor/CmdLine.hs +++ b/src/Propellor/CmdLine.hs @@ -19,6 +19,7 @@ import Propellor.Types.CmdLine import qualified Propellor.Property.Docker as Docker import qualified Propellor.Property.Chroot as Chroot import qualified Propellor.Shim as Shim +import Utility.FileSystemEncoding usage :: Handle -> IO () usage h = hPutStrLn h $ unlines @@ -94,6 +95,7 @@ data CanRebuild = CanRebuild | NoRebuild -- | Runs propellor on hosts, as controlled by command-line options. defaultMain :: [Host] -> IO () defaultMain hostlist = withConcurrentOutput $ do + useFileSystemEncoding Shim.cleanEnv checkDebugMode cmdline <- processCmdLine diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs index fd2fca79..6ac153cc 100644 --- a/src/Propellor/Gpg.hs +++ b/src/Propellor/Gpg.hs @@ -16,7 +16,6 @@ import Utility.Process.NonConcurrent import Utility.Monad import Utility.Misc import Utility.Tmp -import Utility.FileSystemEncoding import Utility.Env import Utility.Directory @@ -183,7 +182,7 @@ gpgDecrypt :: FilePath -> IO String gpgDecrypt f = do gpgbin <- getGpgBin ifM (doesFileExist f) - ( writeReadProcessEnv gpgbin ["--decrypt", f] Nothing Nothing (Just fileEncoding) + ( writeReadProcessEnv gpgbin ["--decrypt", f] Nothing Nothing Nothing , return "" ) @@ -201,6 +200,4 @@ gpgEncrypt f s = do encrypted <- writeReadProcessEnv gpgbin opts Nothing (Just writer) Nothing viaTmp writeFile f encrypted where - writer h = do - fileEncoding h - hPutStr h s + writer h = hPutStr h s diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index 2e9cdbab..8ca51e23 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -57,7 +57,6 @@ import Utility.Misc import Utility.FileMode import Utility.Env import Utility.Table -import Utility.FileSystemEncoding import Utility.Directory -- | Allows a Property to access the value of a specific PrivDataField, @@ -171,7 +170,6 @@ 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 () @@ -274,7 +272,7 @@ readPrivData :: String -> PrivMap readPrivData = fromMaybe M.empty . readish readPrivDataFile :: FilePath -> IO PrivMap -readPrivDataFile f = readPrivData <$> readFileStrictAnyEncoding f +readPrivDataFile f = readPrivData <$> readFileStrict f makePrivDataDir :: IO () makePrivDataDir = createDirectoryIfMissing False privDataDir diff --git a/src/Propellor/Property.hs b/src/Propellor/Property.hs index ae4fc914..8f51035b 100644 --- a/src/Propellor/Property.hs +++ b/src/Propellor/Property.hs @@ -222,7 +222,7 @@ changesFile p f = checkResult getstat comparestat p changesFileContent :: Checkable p i => p i -> FilePath -> Property i changesFileContent p f = checkResult getmd5 comparemd5 p where - getmd5 = catchMaybeIO $ MD5.md5 . MD5.Str <$> readFileStrictAnyEncoding f + getmd5 = catchMaybeIO $ MD5.md5 . MD5.Str <$> readFileStrict f comparemd5 oldmd5 = do newmd5 <- getmd5 return $ if oldmd5 == newmd5 then NoChange else MadeChange diff --git a/src/Propellor/Property/Debootstrap.hs b/src/Propellor/Property/Debootstrap.hs index f8cb6e0e..db114e01 100644 --- a/src/Propellor/Property/Debootstrap.hs +++ b/src/Propellor/Property/Debootstrap.hs @@ -148,7 +148,7 @@ sourceInstall' = withTmpDir "debootstrap" $ \tmpd -> do . filter ("debootstrap_" `isInfixOf`) . filter (".tar." `isInfixOf`) . extractUrls baseurl <$> - readFileStrictAnyEncoding indexfile + readFileStrict indexfile nukeFile indexfile tarfile <- case urls of diff --git a/src/Propellor/Property/Gpg.hs b/src/Propellor/Property/Gpg.hs index 74e9df5a..27baa4ba 100644 --- a/src/Propellor/Property/Gpg.hs +++ b/src/Propellor/Property/Gpg.hs @@ -2,7 +2,6 @@ module Propellor.Property.Gpg where import Propellor.Base import qualified Propellor.Property.Apt as Apt -import Utility.FileSystemEncoding import System.PosixCompat @@ -35,7 +34,6 @@ keyImported key@(GpgKeyId keyid) user@(User u) = prop ( return NoChange , makeChange $ withHandle StdinHandle createProcessSuccess (proc "su" ["-c", "gpg --import", u]) $ \h -> do - fileEncoding h hPutStr h (unlines keylines) hClose h ) diff --git a/src/Propellor/Shim.hs b/src/Propellor/Shim.hs index 27545afb..811ae7f0 100644 --- a/src/Propellor/Shim.hs +++ b/src/Propellor/Shim.hs @@ -9,7 +9,6 @@ module Propellor.Shim (setup, cleanEnv, file) where import Propellor.Base import Utility.LinuxMkLibs import Utility.FileMode -import Utility.FileSystemEncoding import Data.List import System.Posix.Files @@ -57,7 +56,6 @@ shebang = "#!/bin/sh" checkAlreadyShimmed :: FilePath -> IO FilePath -> IO FilePath checkAlreadyShimmed f nope = ifM (doesFileExist f) ( withFile f ReadMode $ \h -> do - fileEncoding h s <- hGetLine h if s == shebang then return f -- cgit v1.2.3