-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_paths.go
64 lines (57 loc) · 1.39 KB
/
node_paths.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package object
import (
"fmt"
"os"
"path/filepath"
"github.com/opensvc/om3/core/rawconfig"
"github.com/rs/zerolog/log"
)
// nodePaths contains lazy initialized object paths on the node filesystem.
type nodePaths struct {
varDir string
logDir string
tmpDir string
dnsUDSDir string
}
func (t *Node) VarDir() string {
if t.paths.varDir != "" {
return t.paths.varDir
}
t.paths.varDir = rawconfig.NodeVarDir()
if err := os.MkdirAll(t.paths.varDir, os.ModePerm); err != nil {
log.Error().Msgf("%s", err)
}
return t.paths.varDir
}
func (t *Node) LogDir() string {
if t.paths.logDir != "" {
return t.paths.logDir
}
p := fmt.Sprintf("%s", rawconfig.Paths.Log)
t.paths.logDir = filepath.FromSlash(p)
if err := os.MkdirAll(t.paths.logDir, os.ModePerm); err != nil {
log.Error().Msgf("%s", err)
}
return t.paths.logDir
}
func (t *Node) TmpDir() string {
if t.paths.tmpDir != "" {
return t.paths.tmpDir
}
p := fmt.Sprintf("%s", rawconfig.Paths.Tmp)
t.paths.tmpDir = filepath.FromSlash(p)
if err := os.MkdirAll(t.paths.tmpDir, os.ModePerm); err != nil {
log.Error().Msgf("%s", err)
}
return t.paths.tmpDir
}
func (t *Node) DNSUDSDir() string {
if t.paths.dnsUDSDir != "" {
return t.paths.dnsUDSDir
}
t.paths.dnsUDSDir = rawconfig.DNSUDSDir()
if err := os.MkdirAll(t.paths.dnsUDSDir, os.ModePerm); err != nil {
log.Error().Msgf("%s", err)
}
return t.paths.dnsUDSDir
}