summaryrefslogtreecommitdiff
path: root/src/Propellor/PrivData/Paths.hs
blob: 7410370bdf1bb7fb2716c3814d295a001f088a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Propellor.PrivData.Paths where

import Utility.Exception
import System.FilePath
import Control.Applicative
import Prelude

privDataDir :: FilePath
privDataDir = "privdata"

privDataFile :: IO FilePath
privDataFile = allowRelocate $ privDataDir </> "privdata.gpg"

privDataKeyring :: IO FilePath
privDataKeyring = allowRelocate $ privDataDir </> "keyring.gpg"

privDataLocal :: FilePath
privDataLocal = privDataDir </> "local"

privDataRelay :: String -> FilePath
privDataRelay host = privDataDir </> "relay" </> host

-- Allow relocating files in privdata, by checking for a file
-- privdata/relocate, which contains the path to a subdirectory that
-- contains the files.
allowRelocate :: FilePath -> IO FilePath
allowRelocate f = reloc . lines
	<$> catchDefaultIO "" (readFile (privDataDir </> "relocate"))
  where
	reloc (p:_) | not (null p) = privDataDir </> p </> takeFileName f
	reloc _ = f