diff --git a/environment/vm/lima/config.go b/environment/vm/lima/config.go index c7c05585..a070eeac 100644 --- a/environment/vm/lima/config.go +++ b/environment/vm/lima/config.go @@ -1,6 +1,7 @@ package lima import ( + "context" "encoding/json" "fmt" "path/filepath" @@ -9,9 +10,13 @@ import ( const configFile = "/etc/colima/colima.json" func (l limaVM) getConf() map[string]string { + log := l.Logger(context.Background()) + obj := map[string]string{} b, err := l.Read(configFile) if err != nil { + log.Tracef("failed to read config file %w", err) + return obj } diff --git a/environment/vm/lima/file.go b/environment/vm/lima/file.go index ded77323..5ee0f1a5 100644 --- a/environment/vm/lima/file.go +++ b/environment/vm/lima/file.go @@ -16,7 +16,7 @@ import ( func (l limaVM) Read(fileName string) (string, error) { s, err := l.RunOutput("sudo", "cat", fileName) if err != nil { - return "", fmt.Errorf("cannot read file: %s", fileName) + return "", fmt.Errorf("cannot read file '%s': %w", fileName, err) } return s, err } @@ -45,16 +45,15 @@ type fileInfo struct { } func newFileInfo(guest environment.GuestActions, filename string) (fileInfo, error) { - statErr := fmt.Errorf("cannot stat file: %s", filename) info := fileInfo{} // "%s,%a,%Y,%F" -> size, permission, modified time, type stat, err := guest.RunOutput("sudo", "stat", "-c", "%s,%a,%Y,%F", filename) if err != nil { - return info, statErr + return info, statError(filename, err) } stats := strings.Split(stat, ",") if len(stats) < 4 { - return info, statErr + return info, statError(filename, err) } info.name = filename info.size, _ = strconv.ParseInt(stats[0], 10, 64) @@ -71,6 +70,10 @@ func newFileInfo(guest environment.GuestActions, filename string) (fileInfo, err return info, nil } +func statError(filename string, err error) error { + return fmt.Errorf("cannot stat file '%s': %w", filename, err) +} + // IsDir implements fs.FileInfo func (f fileInfo) IsDir() bool { return f.isDir }