diff options
author | joe <joe@jerkface.net> | 2016-04-28 00:58:14 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2016-04-28 00:58:14 -0400 |
commit | 39b94e9bb752d1a5590c94d2847d421dbcea8e6f (patch) | |
tree | 408d88aa4b22bf957d66f5f881b7eb7297f911df /lib | |
parent | 368ae2d134ceb7ffbc3a5b1696574e7eb4d3e3d8 (diff) |
write hosts file to cache.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/KeyRing.hs | 12 | ||||
-rw-r--r-- | 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 | |||
107 | 107 | ||
108 | import System.Environment | 108 | import System.Environment |
109 | import Control.Monad | 109 | import Control.Monad |
110 | import Control.Exception ( catch ) | ||
111 | import System.IO.Error ( isDoesNotExistError ) | ||
110 | import Data.Maybe | 112 | import Data.Maybe |
111 | import Data.Either | 113 | import Data.Either |
112 | import Data.Char | 114 | import Data.Char |
@@ -137,7 +139,7 @@ import Data.Text.Encoding ( encodeUtf8 ) | |||
137 | import qualified Data.Map as Map | 139 | import qualified Data.Map as Map |
138 | import qualified Data.ByteString.Lazy as L ( unpack, null, readFile, writeFile | 140 | import qualified Data.ByteString.Lazy as L ( unpack, null, readFile, writeFile |
139 | , ByteString, toChunks, hGetContents, hPut, concat, fromChunks, splitAt | 141 | , ByteString, toChunks, hGetContents, hPut, concat, fromChunks, splitAt |
140 | , index, break, pack ) | 142 | , index, break, pack, empty ) |
141 | import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, hPutStr, singleton, unfoldr, reverse ) | 143 | import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, hPutStr, singleton, unfoldr, reverse ) |
142 | import qualified Codec.Binary.Base32 as Base32 | 144 | import qualified Codec.Binary.Base32 as Base32 |
143 | import qualified Codec.Binary.Base64 as Base64 | 145 | import qualified Codec.Binary.Base64 as Base64 |
@@ -1354,7 +1356,13 @@ mergeHostFiles krd db ctx = do | |||
1354 | guard (istyp $ typ stream) | 1356 | guard (istyp $ typ stream) |
1355 | return f | 1357 | return f |
1356 | 1358 | ||
1357 | hostdbs0 <- mapM (fmap Hosts.decode . readInputFileL ctx) hns | 1359 | readInputFileL' ctx f = |
1360 | readInputFileL ctx f | ||
1361 | `catch` \e -> do when (not $ isDoesNotExistError e) $ do | ||
1362 | return () -- todo report problem | ||
1363 | return L.empty | ||
1364 | |||
1365 | hostdbs0 <- mapM (fmap Hosts.decode . readInputFileL' ctx) hns | ||
1358 | 1366 | ||
1359 | let gpgnames = map getHostnames $ Map.elems db | 1367 | let gpgnames = map getHostnames $ Map.elems db |
1360 | os = do | 1368 | 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 | |||
240 | return (mkpath,commit) | 240 | return (mkpath,commit) |
241 | (mkpath, commit) <- getMkPathAndCommit (fromMaybe "" rootdir ++ "/var/cache/kiki/config") | 241 | (mkpath, commit) <- getMkPathAndCommit (fromMaybe "" rootdir ++ "/var/cache/kiki/config") |
242 | 242 | ||
243 | -- Generete hosts file. | ||
244 | let hostspath = mkpath "hosts" | ||
245 | op = KeyRingOperation | ||
246 | { opFiles = Map.fromList $ | ||
247 | [ ( HomePub, streaminfo { typ=KeyRingFile, spill=KF_All, access=Pub } ) | ||
248 | , ( ArgFile hostspath, streaminfo { typ=Hosts, spill=KF_None, fill=KF_All, access=Pub } ) | ||
249 | ] | ||
250 | , opPassphrases = [] | ||
251 | , opHome = Just $ takeDirectory (rtPubring rt) | ||
252 | , opTransforms = [] | ||
253 | } | ||
254 | KikiResult _ report <- runKeyRing op | ||
255 | outputReport report | ||
256 | |||
243 | let write' wr f bs = do | 257 | let write' wr f bs = do |
244 | createDirectoryIfMissing True $ takeDirectory f | 258 | createDirectoryIfMissing True $ takeDirectory f |
245 | wr f bs | 259 | wr f bs |