1package mox
2
3import (
4 "path/filepath"
5)
6
7// ConfigDirPath returns the path to "f". Either f itself when absolute, or
8// interpreted relative to the directory of the static configuration file
9// (mox.conf).
10func ConfigDirPath(f string) string {
11 return configDirPath(ConfigStaticPath, f)
12}
13
14// Like ConfigDirPath, but relative paths are interpreted relative to the directory
15// of the dynamic configuration file (domains.conf).
16func ConfigDynamicDirPath(f string) string {
17 return configDirPath(ConfigDynamicPath, f)
18}
19
20// DataDirPath returns to the path to "f". Either f itself when absolute, or
21// interpreted relative to the data directory from the currently active
22// configuration.
23func DataDirPath(f string) string {
24 return dataDirPath(ConfigStaticPath, Conf.Static.DataDir, f)
25}
26
27// return f interpreted relative to the directory of the config dir. f is returned
28// unchanged when absolute.
29func configDirPath(configFile, f string) string {
30 if filepath.IsAbs(f) {
31 return f
32 }
33 return filepath.Join(filepath.Dir(configFile), f)
34}
35
36// return f interpreted relative to the data directory that is interpreted relative
37// to the directory of the config dir. f is returned unchanged when absolute.
38func dataDirPath(configFile, dataDir, f string) string {
39 if filepath.IsAbs(f) {
40 return f
41 }
42 return filepath.Join(configDirPath(configFile, dataDir), f)
43}
44