-
Notifications
You must be signed in to change notification settings - Fork 22
/
custom.go
212 lines (184 loc) · 8.45 KB
/
custom.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package paths
import (
"fmt"
"path/filepath"
vgfs "code.vegaprotocol.io/vega/libs/fs"
)
// When opting for a custom Vega home, the all files are located under the
// specified folder. They are sorted, by purpose, in sub-folders. The structure
// of these sub-folder is described in paths.go.
//
// File structure for custom home:
//
// VEGA_HOME
// ├── cache/
// ├── config/
// ├── data/
// └── state/
type CustomPaths struct {
CustomHome string
}
// CreateCacheDirFor builds the path for cache files at the configured home and
// creates intermediate directories.
func (p *CustomPaths) CreateCacheDirFor(relDirPath CachePath) (string, error) {
return CreateCustomCacheDirFor(p.CustomHome, relDirPath)
}
// CreateCachePathFor builds the path for cache directories at the configured home
// and creates intermediate directories.
func (p *CustomPaths) CreateCachePathFor(relFilePath CachePath) (string, error) {
return CreateCustomCachePathFor(p.CustomHome, relFilePath)
}
// CreateConfigDirFor builds the path for configuration files at a given configured
// home and creates intermediate directories.
func (p *CustomPaths) CreateConfigDirFor(relDirPath ConfigPath) (string, error) {
return CreateCustomConfigDirFor(p.CustomHome, relDirPath)
}
// CreateConfigPathFor builds the path for config directories at the configured
// home and creates intermediate directories.
func (p *CustomPaths) CreateConfigPathFor(relFilePath ConfigPath) (string, error) {
return CreateCustomConfigPathFor(p.CustomHome, relFilePath)
}
// CreateDataDirFor builds the path for data files at the configured home and
// creates intermediate directories.
func (p *CustomPaths) CreateDataDirFor(relDirPath DataPath) (string, error) {
return CreateCustomDataDirFor(p.CustomHome, relDirPath)
}
// CreateDataPathFor builds the path for data directories at the configured home
// and creates intermediate directories.
func (p *CustomPaths) CreateDataPathFor(relFilePath DataPath) (string, error) {
return CreateCustomDataPathFor(p.CustomHome, relFilePath)
}
// CreateStateDirFor builds the path for cache files at the configured home and
// creates intermediate directories.
func (p *CustomPaths) CreateStateDirFor(relDirPath StatePath) (string, error) {
return CreateCustomStateDirFor(p.CustomHome, relDirPath)
}
// CreateStatePathFor builds the path for data directories at the configured home
// and creates intermediate directories.
func (p *CustomPaths) CreateStatePathFor(relFilePath StatePath) (string, error) {
return CreateCustomStatePathFor(p.CustomHome, relFilePath)
}
// CachePathFor builds the path for a cache file or directories at the
// configured home. It doesn't create any resources.
func (p *CustomPaths) CachePathFor(relPath CachePath) string {
return CustomCachePathFor(p.CustomHome, relPath)
}
// ConfigPathFor builds the path for a config file or directories at the
// configured home. It doesn't create any resources.
func (p *CustomPaths) ConfigPathFor(relPath ConfigPath) string {
return CustomConfigPathFor(p.CustomHome, relPath)
}
// DataPathFor builds the path for a data file or directories at the configured
// home. It doesn't create any resources.
func (p *CustomPaths) DataPathFor(relPath DataPath) string {
return CustomDataPathFor(p.CustomHome, relPath)
}
// StatePathFor builds the path for a state file or directories at the
// configured home. It doesn't create any resources.
func (p *CustomPaths) StatePathFor(relPath StatePath) string {
return CustomStatePathFor(p.CustomHome, relPath)
}
// CreateCustomCachePathFor builds the path for cache files at a given root path and
// creates intermediate directories. It scoped the files under a "cache" folder,
// and follow the default structure.
func CreateCustomCachePathFor(customHome string, relFilePath CachePath) (string, error) {
fullPath := CustomCachePathFor(customHome, relFilePath)
dir := filepath.Dir(fullPath)
if err := vgfs.EnsureDir(dir); err != nil {
return "", fmt.Errorf("couldn't create directories for file: %w", err)
}
return fullPath, nil
}
// CreateCustomCacheDirFor builds the path for cache directories at a given root path
// and creates intermediate directories. It scoped the files under a "data"
// folder, and follow the default structure.
func CreateCustomCacheDirFor(customHome string, relDirPath CachePath) (string, error) {
path := CustomCachePathFor(customHome, relDirPath)
if err := vgfs.EnsureDir(path); err != nil {
return "", fmt.Errorf("couldn't create directories: %w", err)
}
return path, nil
}
// CreateCustomConfigPathFor builds the path for configuration files at a given root
// path and creates intermediate directories. It scoped the files under a
// "config" folder, and follow the default structure.
func CreateCustomConfigPathFor(customHome string, relFilePath ConfigPath) (string, error) {
fullPath := CustomConfigPathFor(customHome, relFilePath)
dir := filepath.Dir(fullPath)
if err := vgfs.EnsureDir(dir); err != nil {
return "", fmt.Errorf("couldn't create directories for file: %w", err)
}
return fullPath, nil
}
// CreateCustomConfigDirFor builds the path for config directories at a given root path
// and creates intermediate directories. It scoped the files under a "data"
// folder, and follow the default structure.
func CreateCustomConfigDirFor(customHome string, relDirPath ConfigPath) (string, error) {
path := CustomConfigPathFor(customHome, relDirPath)
if err := vgfs.EnsureDir(path); err != nil {
return "", fmt.Errorf("couldn't create directories: %w", err)
}
return path, nil
}
// CreateCustomDataPathFor builds the path for data files at a given root path and
// creates intermediate directories. It scoped the files under a "data" folder,
// and follow the default structure.
func CreateCustomDataPathFor(customHome string, relFilePath DataPath) (string, error) {
fullPath := CustomDataPathFor(customHome, relFilePath)
dir := filepath.Dir(fullPath)
if err := vgfs.EnsureDir(dir); err != nil {
return "", fmt.Errorf("couldn't create directories for file: %w", err)
}
return fullPath, nil
}
// CreateCustomDataDirFor builds the path for data directories at a given root path
// and creates intermediate directories. It scoped the files under a "data"
// folder, and follow the default structure.
func CreateCustomDataDirFor(customHome string, relDirPath DataPath) (string, error) {
path := CustomDataPathFor(customHome, relDirPath)
if err := vgfs.EnsureDir(path); err != nil {
return "", fmt.Errorf("couldn't create directories: %w", err)
}
return path, nil
}
// CreateCustomStatePathFor builds the path for cache files at a given root path and
// creates intermediate directories. It scoped the files under a "cache" folder,
// and follow the default structure.
func CreateCustomStatePathFor(customHome string, relFilePath StatePath) (string, error) {
fullPath := CustomStatePathFor(customHome, relFilePath)
dir := filepath.Dir(fullPath)
if err := vgfs.EnsureDir(dir); err != nil {
return "", fmt.Errorf("couldn't create directories for file: %w", err)
}
return fullPath, nil
}
// CreateCustomStateDirFor builds the path for data directories at a given root path
// and creates intermediate directories. It scoped the files under a "data"
// folder, and follow the default structure.
func CreateCustomStateDirFor(customHome string, relDirPath StatePath) (string, error) {
path := CustomStatePathFor(customHome, relDirPath)
if err := vgfs.EnsureDir(path); err != nil {
return "", fmt.Errorf("couldn't create directories: %w", err)
}
return path, nil
}
// CustomCachePathFor builds the path for a cache file or directories at a given
// root path. It doesn't create any resources.
func CustomCachePathFor(customHome string, relPath CachePath) string {
return filepath.Join(customHome, "cache", relPath.String())
}
// CustomConfigPathFor builds the path for a config file or directories at a given
// root path. It doesn't create any resources.
func CustomConfigPathFor(customHome string, relPath ConfigPath) string {
return filepath.Join(customHome, "config", relPath.String())
}
// CustomDataPathFor builds the path for a data file or directories at a given
// root path. It doesn't create any resources.
func CustomDataPathFor(customHome string, relPath DataPath) string {
return filepath.Join(customHome, "data", relPath.String())
}
// CustomStatePathFor builds the path for a state file or directories at a given
// root path. It doesn't create any resources.
func CustomStatePathFor(customHome string, relPath StatePath) string {
return filepath.Join(customHome, "state", relPath.String())
}