Skip to content

Commit b09bd9e

Browse files
committed
Move directory function from store → store/dirnames
This is to break the cycle that store depends on limayaml, and networks depends on store, so limayaml cannot depend on networks to allow network name validation. Signed-off-by: Jan Dubois <[email protected]>
1 parent 3ad14f6 commit b09bd9e

File tree

7 files changed

+61
-51
lines changed

7 files changed

+61
-51
lines changed

cmd/limactl/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66
"strings"
77

8-
"github.com/lima-vm/lima/pkg/store"
8+
"github.com/lima-vm/lima/pkg/store/dirnames"
99
"github.com/lima-vm/lima/pkg/version"
1010
"github.com/sirupsen/logrus"
1111
"github.com/spf13/cobra"
@@ -41,7 +41,7 @@ func newApp() *cobra.Command {
4141
}
4242
// Make sure either $HOME or $LIMA_HOME is defined, so we don't need
4343
// to check for errors later
44-
if _, err := store.LimaDir(); err != nil {
44+
if _, err := dirnames.LimaDir(); err != nil {
4545
return err
4646
}
4747
return nil

pkg/networks/commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package networks
22

33
import (
44
"fmt"
5-
"github.com/lima-vm/lima/pkg/store"
5+
"github.com/lima-vm/lima/pkg/store/dirnames"
66
)
77

88
const (
@@ -29,7 +29,7 @@ func (config *NetworksConfig) PIDFile(name, daemon string) string {
2929
}
3030

3131
func (config *NetworksConfig) LogFile(name, daemon, stream string) string {
32-
networksDir, _ := store.LimaNetworksDir()
32+
networksDir, _ := dirnames.LimaNetworksDir()
3333
return fmt.Sprintf("%s/%s_%s.%s.log", networksDir, name, daemon, stream)
3434
}
3535

pkg/networks/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"runtime"
1111
"sync"
1212

13-
"github.com/lima-vm/lima/pkg/store"
13+
"github.com/lima-vm/lima/pkg/store/dirnames"
1414
"github.com/lima-vm/lima/pkg/store/filenames"
1515
)
1616

@@ -27,7 +27,7 @@ var cache struct {
2727
func load() {
2828
cache.Do(func() {
2929
var configDir string
30-
configDir, cache.err = store.LimaConfigDir()
30+
configDir, cache.err = dirnames.LimaConfigDir()
3131
if cache.err != nil {
3232
return
3333
}

pkg/networks/reconcile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync"
1212

1313
"github.com/lima-vm/lima/pkg/store"
14+
"github.com/lima-vm/lima/pkg/store/dirnames"
1415
"github.com/sirupsen/logrus"
1516
)
1617

@@ -84,7 +85,7 @@ func (config *NetworksConfig) startDaemon(ctx context.Context, name, daemon stri
8485
return err
8586
}
8687

87-
networksDir, _ := store.LimaNetworksDir()
88+
networksDir, _ := dirnames.LimaNetworksDir()
8889
if err := os.MkdirAll(networksDir, 0755); err != nil {
8990
return err
9091
}

pkg/sshutil/sshutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/lima-vm/lima/pkg/lockutil"
1313
"github.com/lima-vm/lima/pkg/osutil"
14-
"github.com/lima-vm/lima/pkg/store"
14+
"github.com/lima-vm/lima/pkg/store/dirnames"
1515
"github.com/lima-vm/lima/pkg/store/filenames"
1616
"github.com/sirupsen/logrus"
1717
)
@@ -41,7 +41,7 @@ func readPublicKey(f string) (PubKey, error) {
4141
// an identity explicitly.
4242
func DefaultPubKeys(loadDotSSH bool) ([]PubKey, error) {
4343
// Read $LIMA_HOME/_config/user.pub
44-
configDir, err := store.LimaConfigDir()
44+
configDir, err := dirnames.LimaConfigDir()
4545
if err != nil {
4646
return nil, err
4747
}
@@ -103,7 +103,7 @@ func DefaultPubKeys(loadDotSSH bool) ([]PubKey, error) {
103103
}
104104

105105
func CommonArgs(useDotSSH bool) ([]string, error) {
106-
configDir, err := store.LimaConfigDir()
106+
configDir, err := dirnames.LimaConfigDir()
107107
if err != nil {
108108
return nil, err
109109
}

pkg/store/dirnames/dirnames.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package dirnames
2+
3+
import (
4+
"path/filepath"
5+
"os"
6+
7+
"github.com/lima-vm/lima/pkg/store/filenames"
8+
)
9+
10+
// DotLima is a directory that appears under the home directory.
11+
const DotLima = ".lima"
12+
13+
// LimaDir returns the abstract path of `~/.lima` (or $LIMA_HOME, if set).
14+
//
15+
// NOTE: We do not use `~/Library/Application Support/Lima` on macOS.
16+
// We use `~/.lima` so that we can have enough space for the length of the socket path,
17+
// which can be only 104 characters on macOS.
18+
func LimaDir() (string, error) {
19+
dir := os.Getenv("LIMA_HOME")
20+
if dir == "" {
21+
homeDir, err := os.UserHomeDir()
22+
if err != nil {
23+
return "", err
24+
}
25+
dir = filepath.Join(homeDir, DotLima)
26+
}
27+
return dir, nil
28+
}
29+
30+
// LimaConfigDir returns the path of the config directory, $LIMA_HOME/_config.
31+
func LimaConfigDir() (string, error) {
32+
limaDir, err := LimaDir()
33+
if err != nil {
34+
return "", err
35+
}
36+
return filepath.Join(limaDir, filenames.ConfigDir), nil
37+
}
38+
39+
// LimaNetworksDir returns the path of the networks log directory, $LIMA_HOME/_networks.
40+
func LimaNetworksDir() (string, error) {
41+
limaDir, err := LimaDir()
42+
if err != nil {
43+
return "", err
44+
}
45+
return filepath.Join(limaDir, filenames.NetworksDir), nil
46+
}
47+

pkg/store/store.go

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,12 @@ import (
77

88
"github.com/containerd/containerd/identifiers"
99
"github.com/lima-vm/lima/pkg/limayaml"
10-
"github.com/lima-vm/lima/pkg/store/filenames"
10+
"github.com/lima-vm/lima/pkg/store/dirnames"
1111
)
1212

13-
// DotLima is a directory that appears under the home directory.
14-
const DotLima = ".lima"
15-
16-
// LimaDir returns the abstract path of `~/.lima` (or $LIMA_HOME, if set).
17-
//
18-
// NOTE: We do not use `~/Library/Application Support/Lima` on macOS.
19-
// We use `~/.lima` so that we can have enough space for the length of the socket path,
20-
// which can be only 104 characters on macOS.
21-
func LimaDir() (string, error) {
22-
dir := os.Getenv("LIMA_HOME")
23-
if dir == "" {
24-
homeDir, err := os.UserHomeDir()
25-
if err != nil {
26-
return "", err
27-
}
28-
dir = filepath.Join(homeDir, DotLima)
29-
}
30-
return dir, nil
31-
}
32-
33-
// LimaConfigDir returns the path of the config directory, $LIMA_HOME/_config.
34-
func LimaConfigDir() (string, error) {
35-
limaDir, err := LimaDir()
36-
if err != nil {
37-
return "", err
38-
}
39-
return filepath.Join(limaDir, filenames.ConfigDir), nil
40-
}
41-
42-
// LimaNetworksDir returns the path of the networks log directory, $LIMA_HOME/_networks.
43-
func LimaNetworksDir() (string, error) {
44-
limaDir, err := LimaDir()
45-
if err != nil {
46-
return "", err
47-
}
48-
return filepath.Join(limaDir, filenames.NetworksDir), nil
49-
}
50-
5113
// Instances returns the names of the instances under LimaDir.
5214
func Instances() ([]string, error) {
53-
limaDir, err := LimaDir()
15+
limaDir, err := dirnames.LimaDir()
5416
if err != nil {
5517
return nil, err
5618
}
@@ -74,7 +36,7 @@ func InstanceDir(name string) (string, error) {
7436
if err := identifiers.Validate(name); err != nil {
7537
return "", err
7638
}
77-
limaDir, err := LimaDir()
39+
limaDir, err := dirnames.LimaDir()
7840
if err != nil {
7941
return "", err
8042
}

0 commit comments

Comments
 (0)