From 2f441f72428cbb3e0076dbb4b8a9d8a08ee1c62e Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 21 Sep 2012 06:07:12 +0200 Subject: [PATCH] Add support for GANETI_ROOTDIR in Haskell code unsafePerformIO is required to go from the IO monad to pure code. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- htools/Ganeti/Path.hs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htools/Ganeti/Path.hs b/htools/Ganeti/Path.hs index ee102d50a..fcb759b1a 100644 --- a/htools/Ganeti/Path.hs +++ b/htools/Ganeti/Path.hs @@ -23,32 +23,32 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -} -module Ganeti.Path - ( defaultLuxiSocket - , defaultQuerySocket - , dataDir - , logDir - , runDir - , confdHmacKey - , clusterConfFile - , nodedCertFile - ) where +module Ganeti.Path where import qualified Ganeti.Constants as C import System.FilePath +import System.Posix.Env (getEnvDefault) +import System.IO.Unsafe +{-# NOINLINE getRootDir #-} +getRootDir :: FilePath +getRootDir = unsafePerformIO $ getEnvDefault "GANETI_ROOTDIR" "" + +-- | Prefixes a path with the current root directory +addNodePrefix :: FilePath -> FilePath +addNodePrefix path = getRootDir ++ path -- | Directory for data dataDir :: FilePath -dataDir = C.autoconfLocalstatedir </> "lib" </> "ganeti" +dataDir = addNodePrefix $ C.autoconfLocalstatedir </> "lib" </> "ganeti" -- | Directory for runtime files runDir :: FilePath -runDir = C.autoconfLocalstatedir </> "run" </> "ganeti" +runDir = addNodePrefix $ C.autoconfLocalstatedir </> "run" </> "ganeti" -- | Directory for log files logDir :: FilePath -logDir = C.autoconfLocalstatedir </> "log" </> "ganeti" +logDir = addNodePrefix $ C.autoconfLocalstatedir </> "log" </> "ganeti" -- | Directory for Unix sockets socketDir :: FilePath -- GitLab