From 0daf924b43d0750b285a5e857eb9946a9a71e6cc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 7 Mar 2016 18:40:24 -0400 Subject: privdata/relocate better than symlinks because this way no conflict can ever occur and, commit from hook --- src/Propellor/PrivData/Paths.hs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/Propellor/PrivData') diff --git a/src/Propellor/PrivData/Paths.hs b/src/Propellor/PrivData/Paths.hs index 3d0d8a58..7410370b 100644 --- a/src/Propellor/PrivData/Paths.hs +++ b/src/Propellor/PrivData/Paths.hs @@ -1,15 +1,31 @@ module Propellor.PrivData.Paths where +import Utility.Exception import System.FilePath +import Control.Applicative +import Prelude privDataDir :: FilePath privDataDir = "privdata" -privDataFile :: FilePath -privDataFile = privDataDir "privdata.gpg" +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 -- cgit v1.2.3