From 39b94e9bb752d1a5590c94d2847d421dbcea8e6f Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 28 Apr 2016 00:58:14 -0400 Subject: write hosts file to cache. --- lib/KeyRing.hs | 12 ++++++++++-- lib/Kiki.hs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/KeyRing.hs b/lib/KeyRing.hs index fbd23fe..04ac7c6 100644 --- a/lib/KeyRing.hs +++ b/lib/KeyRing.hs @@ -107,6 +107,8 @@ module KeyRing import System.Environment import Control.Monad +import Control.Exception ( catch ) +import System.IO.Error ( isDoesNotExistError ) import Data.Maybe import Data.Either import Data.Char @@ -137,7 +139,7 @@ import Data.Text.Encoding ( encodeUtf8 ) import qualified Data.Map as Map import qualified Data.ByteString.Lazy as L ( unpack, null, readFile, writeFile , ByteString, toChunks, hGetContents, hPut, concat, fromChunks, splitAt - , index, break, pack ) + , index, break, pack, empty ) import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, hPutStr, singleton, unfoldr, reverse ) import qualified Codec.Binary.Base32 as Base32 import qualified Codec.Binary.Base64 as Base64 @@ -1354,7 +1356,13 @@ mergeHostFiles krd db ctx = do guard (istyp $ typ stream) return f - hostdbs0 <- mapM (fmap Hosts.decode . readInputFileL ctx) hns + readInputFileL' ctx f = + readInputFileL ctx f + `catch` \e -> do when (not $ isDoesNotExistError e) $ do + return () -- todo report problem + return L.empty + + hostdbs0 <- mapM (fmap Hosts.decode . readInputFileL' ctx) hns let gpgnames = map getHostnames $ Map.elems db os = do diff --git a/lib/Kiki.hs b/lib/Kiki.hs index 9fb71be..8090aac 100644 --- a/lib/Kiki.hs +++ b/lib/Kiki.hs @@ -240,6 +240,20 @@ refreshCache rt rootdir = do return (mkpath,commit) (mkpath, commit) <- getMkPathAndCommit (fromMaybe "" rootdir ++ "/var/cache/kiki/config") + -- Generete hosts file. + let hostspath = mkpath "hosts" + op = KeyRingOperation + { opFiles = Map.fromList $ + [ ( HomePub, streaminfo { typ=KeyRingFile, spill=KF_All, access=Pub } ) + , ( ArgFile hostspath, streaminfo { typ=Hosts, spill=KF_None, fill=KF_All, access=Pub } ) + ] + , opPassphrases = [] + , opHome = Just $ takeDirectory (rtPubring rt) + , opTransforms = [] + } + KikiResult _ report <- runKeyRing op + outputReport report + let write' wr f bs = do createDirectoryIfMissing True $ takeDirectory f wr f bs -- cgit v1.2.3