diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Kiki.hs | 20 |
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 | |||
18 | import System.Directory | 18 | import System.Directory |
19 | import System.FilePath.Posix | 19 | import System.FilePath.Posix |
20 | import System.IO | 20 | import System.IO |
21 | import System.IO.Temp | ||
21 | import System.Posix.User | 22 | import System.Posix.User |
22 | import System.Process | 23 | import System.Process |
24 | import System.Posix.Files | ||
23 | import qualified Codec.Binary.Base64 as Base64 | 25 | import qualified Codec.Binary.Base64 as Base64 |
24 | import qualified Data.ByteString.Lazy as L | 26 | import qualified Data.ByteString.Lazy as L |
25 | import qualified Data.ByteString.Lazy.Char8 as Char8 | 27 | import qualified Data.ByteString.Lazy.Char8 as Char8 |
@@ -212,9 +214,19 @@ importAndRefresh root cmn = do | |||
212 | refreshCache :: KeyRingRuntime -> Maybe FilePath -> IO () | 214 | refreshCache :: KeyRingRuntime -> Maybe FilePath -> IO () |
213 | refreshCache rt rootdir = do | 215 | refreshCache 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 | ||
352 | strongswanForContact addr oname = Char8.unlines | 364 | strongswanForContact addr oname = Char8.unlines |
353 | [ "conn " <> p oname | 365 | [ "conn " <> p oname |