generated from srid/ema-template
/
Loc.hs
32 lines (28 loc) · 931 Bytes
/
Loc.hs
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
32
-- | Notebook location
module Emanote.Source.Loc where
import qualified Paths_emanote
import System.FilePath ((</>))
-- | Location of the notebook, even if it contains a subset of files.
--
-- The order here matters. Top = higher precedence.
data Loc
= -- | This always refers to current working directory
LocUser
| -- | The location of the emanote's default files directory containing
-- templates, data, etc.
LocEmanoteDefault FilePath
deriving (Eq, Ord, Show)
-- | Return the location layers to union-mount
locLayers :: MonadIO m => m (Set (Loc, FilePath))
locLayers = do
defaultFiles <- liftIO Paths_emanote.getDataDir
pure $
fromList
[ (LocUser, "."),
(LocEmanoteDefault defaultFiles, defaultFiles)
]
-- | Return the effective path of a file.
locResolve :: (Loc, FilePath) -> FilePath
locResolve (loc, fp) = case loc of
LocUser -> fp
LocEmanoteDefault base -> base </> fp