This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
/
paths.go
128 lines (111 loc) · 3.92 KB
/
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
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
// Copyright 2017 CoreOS Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package torcx
import (
"path/filepath"
)
const (
// DefaultRunDir is the default path where torcx unpacks/propagates all runtime assets.
DefaultRunDir = "/run/torcx/"
// DefaultBaseDir is the default torcx base directory
DefaultBaseDir = "/var/lib/torcx/"
// DefaultConfDir is the default torcx config directory
DefaultConfDir = "/etc/torcx/"
// OemStoreDir is the OEM store path
OemStoreDir = OemDir + "store"
// OemProfilesDir is the OEM profiles path
OemProfilesDir = OemDir + "profiles"
// OemRemotesDir is the OEM remotes path
OemRemotesDir = OemDir + "remotes"
// defaultCfgPath is the default path for common torcx config
defaultCfgPath = DefaultConfDir + "config.json"
)
// VendorRemotesDir is the vendor remotes path
func VendorRemotesDir(usrMountpoint string) string {
if usrMountpoint == "" {
usrMountpoint = VendorUsrDir
}
return filepath.Join(usrMountpoint, "share", "torcx", "remotes")
}
// VendorProfilesDir is the vendor profiles path
func VendorProfilesDir(usrMountpoint string) string {
if usrMountpoint == "" {
usrMountpoint = VendorUsrDir
}
return filepath.Join(usrMountpoint, "share", "torcx", "profiles")
}
// VendorStoreDir is the vendor store path
func VendorStoreDir(usrMountpoint string) string {
if usrMountpoint == "" {
usrMountpoint = VendorUsrDir
}
return filepath.Join(usrMountpoint, "share", "torcx", "store")
}
// RunUnpackDir is the directory where root filesystems are unpacked.
func (cc *CommonConfig) RunUnpackDir() string {
return filepath.Join(cc.RunDir, "unpack")
}
// RunBinDir is the directory where binaries are symlinked.
func (cc *CommonConfig) RunBinDir() string {
return filepath.Join(cc.RunDir, "bin")
}
// ProfileDirs are the list of directories where we look for profiles.
func (cc *CommonConfig) ProfileDirs() []string {
return []string{
VendorProfilesDir(cc.UsrDir),
OemProfilesDir,
cc.UserProfileDir(),
}
}
// RunProfile is the file where we copy the contents of the applied profile.
func (cc *CommonConfig) RunProfile() string {
return filepath.Join(cc.RunDir, "profile.json")
}
// UserStorePath is the path where user-fetched archives are written.
// An optional target version can be specified for versioned user store.
func (cc *CommonConfig) UserStorePath(version string) string {
storePath := filepath.Join(cc.BaseDir, "store")
if version != "" {
storePath = filepath.Join(storePath, version)
}
return storePath
}
// UserProfileDir is where user profiles are written.
func (cc *CommonConfig) UserProfileDir() string {
return filepath.Join(cc.ConfDir, "profiles")
}
// NextProfile is the path for the `next-profile` selector configuration file.
func (cc *CommonConfig) NextProfile() string {
return filepath.Join(cc.ConfDir, "next-profile")
}
// RemotesDirs returns the list of directories where we look for remotes manifests.
func (cc *CommonConfig) RemotesDirs() []string {
dirs := []string{}
if cc != nil {
dirs = append(dirs, VendorRemotesDir(cc.UsrDir))
}
dirs = append(dirs, OemRemotesDir)
if cc != nil {
dirs = append(dirs, filepath.Join(cc.ConfDir, "remotes"))
}
return dirs
}
// VendorOsReleasePath returns the path to vendor os-release file
// for the specific OS partition mounted at `usrMountpoint`.
func VendorOsReleasePath(usrMountpoint string) string {
if usrMountpoint == "" {
usrMountpoint = VendorUsrDir
}
return filepath.Join(usrMountpoint, "lib", "os-release")
}