Skip to content

Commit

Permalink
Record lima working directory for instance
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Aug 30, 2024
1 parent 7225aae commit e249752
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/instance/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ func Create(ctx context.Context, instName string, yBytes []byte, saveBrokenYAML
if err := os.WriteFile(filePath, yBytes, 0o644); err != nil {
return nil, err
}
wd, err := os.Getwd()
if err != nil {
return nil, err
}
if err := os.WriteFile(filepath.Join(instDir, filenames.LimaWorkDir), []byte(wd), 0o644); err != nil {
return nil, err
}
if err := os.WriteFile(filepath.Join(instDir, filenames.LimaVersion), []byte(version.Version), 0o444); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/store/filenames/filenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
const (
LimaYAML = "lima.yaml"
LimaVersion = "lima-version" // Lima version used to create instance
LimaWorkDir = "lima-workdir" // Lima workdir used to create instance
CIDataISO = "cidata.iso"
CIDataISODir = "cidata"
BaseDisk = "basedisk"
Expand Down
10 changes: 10 additions & 0 deletions pkg/store/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ func Inspect(instName string) (*Instance, error) {
if err != nil {
return nil, err
}
// Read working directory from instance directory, if existing
limaWorkDirFile := filepath.Join(instDir, filenames.LimaWorkDir)
if workdir, err := os.ReadFile(limaWorkDirFile); err == nil {
wd := strings.TrimSuffix(string(workdir), "\n")
if err := os.Chdir(wd); err != nil {
logrus.Warnf("failed to change workdir to %q from %q", wd, limaWorkDirFile)
}
} else if !errors.Is(err, os.ErrNotExist) {
inst.Errors = append(inst.Errors, err)
}
// Make sure inst.Dir is set, even when YAML validation fails
inst.Dir = instDir
yamlPath := filepath.Join(instDir, filenames.LimaYAML)
Expand Down
1 change: 1 addition & 0 deletions website/content/en/docs/dev/internals/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ An instance directory contains the following files:

Metadata:
- `lima-version`: the Lima version used to create this instance
- `lima-workdir`: the Lima workdir used to create this instance
- `lima.yaml`: the YAML
- `protected`: empty file, used by `limactl protect`

Expand Down

0 comments on commit e249752

Please sign in to comment.