1515 limitations under the License.
1616*/
1717
18- // Package hoststore provides the interface for /var/lib/nerdctl/etchosts .
18+ // Package hoststore provides the interface for /var/lib/nerdctl/<ADDRHASH>/ etchosts .
1919// Prioritize simplicity over scalability.
2020package hostsstore
2121
@@ -32,18 +32,18 @@ import (
3232)
3333
3434const (
35- // hostsDirBasename is the base name of /var/lib/nerdctl/etchosts
35+ // hostsDirBasename is the base name of /var/lib/nerdctl/<ADDRHASH>/ etchosts
3636 hostsDirBasename = "etchosts"
37- // metaJSON is stored as /var/lib/nerdctl/etchosts/<NS>/<ID>/meta.json
37+ // metaJSON is stored as /var/lib/nerdctl/<ADDRHASH>/ etchosts/<NS>/<ID>/meta.json
3838 metaJSON = "meta.json"
3939)
4040
41- // HostsPath returns "/var/lib/nerdctl/etchosts/<NS>/<ID>/hosts"
42- func HostsPath (dataRoot , ns , id string ) string {
43- if dataRoot == "" || ns == "" || id == "" {
41+ // HostsPath returns "/var/lib/nerdctl/<ADDRHASH>/ etchosts/<NS>/<ID>/hosts"
42+ func HostsPath (dataStore , ns , id string ) string {
43+ if dataStore == "" || ns == "" || id == "" {
4444 panic (errdefs .ErrInvalidArgument )
4545 }
46- return filepath .Join (dataRoot , hostsDirBasename , ns , id , "hosts" )
46+ return filepath .Join (dataStore , hostsDirBasename , ns , id , "hosts" )
4747}
4848
4949// ensureFile ensures a file with permission 0644.
@@ -66,23 +66,23 @@ func ensureFile(path string) error {
6666
6767// EnsureHostsFile is used for creating mount-bindable /etc/hosts file.
6868// The file is initialized with no content.
69- func EnsureHostsFile (dataRoot , ns , id string ) (string , error ) {
70- lockDir := filepath .Join (dataRoot , hostsDirBasename )
69+ func EnsureHostsFile (dataStore , ns , id string ) (string , error ) {
70+ lockDir := filepath .Join (dataStore , hostsDirBasename )
7171 if err := os .MkdirAll (lockDir , 0700 ); err != nil {
7272 return "" , err
7373 }
74- path := HostsPath (dataRoot , ns , id )
74+ path := HostsPath (dataStore , ns , id )
7575 fn := func () error {
7676 return ensureFile (path )
7777 }
7878 err := lockutil .WithDirLock (lockDir , fn )
7979 return path , err
8080}
8181
82- func NewStore (dataRoot string ) (Store , error ) {
82+ func NewStore (dataStore string ) (Store , error ) {
8383 store := & store {
84- dataRoot : dataRoot ,
85- hostsD : filepath .Join (dataRoot , hostsDirBasename ),
84+ dataStore : dataStore ,
85+ hostsD : filepath .Join (dataStore , hostsDirBasename ),
8686 }
8787 return store , os .MkdirAll (store .hostsD , 0700 )
8888}
@@ -101,15 +101,15 @@ type Store interface {
101101}
102102
103103type store struct {
104- // dataRoot is /var/lib/nerdctl
105- dataRoot string
106- // hostsD is /var/lib/nerdctl/etchosts
104+ // dataStore is /var/lib/nerdctl/<ADDRHASH>
105+ dataStore string
106+ // hostsD is /var/lib/nerdctl/<ADDRHASH>/ etchosts
107107 hostsD string
108108}
109109
110110func (x * store ) Acquire (meta Meta ) error {
111111 fn := func () error {
112- hostsPath := HostsPath (x .dataRoot , meta .Namespace , meta .ID )
112+ hostsPath := HostsPath (x .dataStore , meta .Namespace , meta .ID )
113113 if err := ensureFile (hostsPath ); err != nil {
114114 return err
115115 }
0 commit comments