Skip to content

Commit

Permalink
Don't fail if $HOME environment variable is unset (#789)
Browse files Browse the repository at this point in the history
Fixes #788

This removes the dependency on the `directory` library's utility
functions (which require `HOME` to be set)
  • Loading branch information
Gabriella439 authored Jan 21, 2019
1 parent bebfbf2 commit 095ee6d
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions dhall/src/Dhall/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,6 @@ getCacheFile hash = do

cacheDirectory <- getCacheDirectory

assertDirectory cacheDirectory

let dhallDirectory = cacheDirectory </> "dhall"

assertDirectory dhallDirectory
Expand All @@ -582,22 +580,23 @@ getCacheFile hash = do

return cacheFile

getCacheDirectory :: MonadIO io => io FilePath
#if MIN_VERSION_directory(1,2,3)
getCacheDirectory = liftIO (Directory.getXdgDirectory Directory.XdgCache "")
#else
getCacheDirectory = liftIO $ do
maybeXDGCacheHome <- System.Environment.lookupEnv "XDG_CACHE_HOME"
getCacheDirectory :: (Alternative m, MonadIO m) => m FilePath
getCacheDirectory = alternative₀ <|> alternative₁
where
alternative₀ = do
maybeXDGCacheHome <- do
liftIO (System.Environment.lookupEnv "XDG_CACHE_HOME")

case maybeXDGCacheHome of
Nothing -> do
homeDirectory <- Directory.getHomeDirectory
case maybeXDGCacheHome of
Just xdgCacheHome -> return xdgCacheHome
Nothing -> empty

return (homeDirectory </> ".cache")
alternative₁ = do
maybeHomeDirectory <- liftIO (System.Environment.lookupEnv "HOME")

Just xdgCacheHome -> do
return xdgCacheHome
#endif
case maybeHomeDirectory of
Just homeDirectory -> return (homeDirectory </> ".cache")
Nothing -> empty

exprFromUncachedImport :: Import -> StateT (Status IO) IO (Expr Src Import)
exprFromUncachedImport (Import {..}) = do
Expand Down

0 comments on commit 095ee6d

Please sign in to comment.