summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Kiki.hs20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/Kiki.hs b/lib/Kiki.hs
index 0e06ee2..34594cc 100644
--- a/lib/Kiki.hs
+++ b/lib/Kiki.hs
@@ -18,8 +18,10 @@ import Data.Ord
18import System.Directory 18import System.Directory
19import System.FilePath.Posix 19import System.FilePath.Posix
20import System.IO 20import System.IO
21import System.IO.Temp
21import System.Posix.User 22import System.Posix.User
22import System.Process 23import System.Process
24import System.Posix.Files
23import qualified Codec.Binary.Base64 as Base64 25import qualified Codec.Binary.Base64 as Base64
24import qualified Data.ByteString.Lazy as L 26import qualified Data.ByteString.Lazy as L
25import qualified Data.ByteString.Lazy.Char8 as Char8 27import qualified Data.ByteString.Lazy.Char8 as Char8
@@ -212,9 +214,19 @@ importAndRefresh root cmn = do
212refreshCache :: KeyRingRuntime -> Maybe FilePath -> IO () 214refreshCache :: KeyRingRuntime -> Maybe FilePath -> IO ()
213refreshCache rt rootdir = do 215refreshCache rt rootdir = do
214 216
215 let mkpath pth = fromMaybe "" rootdir ++ "/var/cache/kiki/"++pth 217 let getMkPathAndCommit destdir = do
216 218 let cachedir = takeDirectory destdir
217 write' wr f bs = do 219 unslash ('/':xs) = xs
220 unslash xs = xs
221 createDirectoryIfMissing True cachedir
222 tmpdir <- createTempDirectory cachedir "tmp.dir"
223 createSymbolicLink tmpdir (tmpdir ++ ".link")
224 let mkpath pth = tmpdir </> unslash pth
225 commit = rename (tmpdir ++ ".link") destdir
226 return (mkpath,commit)
227 (mkpath, commit) <- getMkPathAndCommit (fromMaybe "" rootdir ++ "/var/cache/kiki/config")
228
229 let write' wr f bs = do
218 createDirectoryIfMissing True $ takeDirectory f 230 createDirectoryIfMissing True $ takeDirectory f
219 wr f bs 231 wr f bs
220 write = write' writeFile 232 write = write' writeFile
@@ -347,7 +359,7 @@ refreshCache rt rootdir = do
347 , " auto=route" 359 , " auto=route"
348 , "" 360 , ""
349 ] ++ filter (not . Char8.null) cons 361 ] ++ filter (not . Char8.null) cons
350 return () 362 commit
351 363
352strongswanForContact addr oname = Char8.unlines 364strongswanForContact addr oname = Char8.unlines
353 [ "conn " <> p oname 365 [ "conn " <> p oname