mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 08:23:48 +03:00
5f7831a7f0
needed for upcoming changes, where (now) package admin needs to import package store. before, because package store imports mox- (for accessing the active config), that would lead to a cyclic import. package mox- keeps its active config, package admin has the higher-level config-changing functions.
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package mox
|
|
|
|
import (
|
|
"path/filepath"
|
|
)
|
|
|
|
// ConfigDirPath returns the path to "f". Either f itself when absolute, or
|
|
// interpreted relative to the directory of the static configuration file
|
|
// (mox.conf).
|
|
func ConfigDirPath(f string) string {
|
|
return configDirPath(ConfigStaticPath, f)
|
|
}
|
|
|
|
// Like ConfigDirPath, but relative paths are interpreted relative to the directory
|
|
// of the dynamic configuration file (domains.conf).
|
|
func ConfigDynamicDirPath(f string) string {
|
|
return configDirPath(ConfigDynamicPath, f)
|
|
}
|
|
|
|
// DataDirPath returns to the path to "f". Either f itself when absolute, or
|
|
// interpreted relative to the data directory from the currently active
|
|
// configuration.
|
|
func DataDirPath(f string) string {
|
|
return dataDirPath(ConfigStaticPath, Conf.Static.DataDir, f)
|
|
}
|
|
|
|
// return f interpreted relative to the directory of the config dir. f is returned
|
|
// unchanged when absolute.
|
|
func configDirPath(configFile, f string) string {
|
|
if filepath.IsAbs(f) {
|
|
return f
|
|
}
|
|
return filepath.Join(filepath.Dir(configFile), f)
|
|
}
|
|
|
|
// return f interpreted relative to the data directory that is interpreted relative
|
|
// to the directory of the config dir. f is returned unchanged when absolute.
|
|
func dataDirPath(configFile, dataDir, f string) string {
|
|
if filepath.IsAbs(f) {
|
|
return f
|
|
}
|
|
return filepath.Join(configDirPath(configFile, dataDir), f)
|
|
}
|