Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cmd runner output reader #5058

Merged
merged 7 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions providers/os/connection/device/linux/device_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package linux
import (
"bytes"
"fmt"
"io"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -99,6 +100,8 @@ func (d *LinuxDeviceManager) IdentifyMountTargets(opts map[string]string) ([]*sn
}

func (d *LinuxDeviceManager) attemptExpandPartitions(partitions []*snapshot.PartitionInfo) ([]*snapshot.PartitionInfo, error) {
log.Debug().Msg("attempting to expand partitions infos")

fstabEntries, err := d.hintFSTypes(partitions)
if err != nil {
log.Warn().Err(err).Msg("could not find fstab")
Expand Down Expand Up @@ -140,6 +143,7 @@ func (d *LinuxDeviceManager) hintFSTypes(partitions []*snapshot.PartitionInfo) (
}

if ok := d.attemptFindOSTree(dir, partition); ok {
log.Debug().Str("device", partition.Name).Msg("ostree found")
return nil, nil
}

Expand All @@ -154,8 +158,8 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr
log.Error().Err(err).Msg("error searching for fstab")
return nil, nil
}
var out []byte
_, err = cmd.Stdout.Read(out)

out, err := io.ReadAll(cmd.Stdout)
if err != nil {
log.Error().Err(err).Msg("error reading find output")
return nil, nil
Expand All @@ -182,6 +186,8 @@ func (d *LinuxDeviceManager) attemptFindFstab(dir string) ([]resources.FstabEntr
}

func (d *LinuxDeviceManager) attemptFindOSTree(dir string, partition *snapshot.PartitionInfo) bool {
log.Debug().Str("device", partition.Name).Msg("attempting to find ostree")

info, err := os.Stat(path.Join(dir, "ostree"))
if err != nil {
if os.IsNotExist(err) {
Expand All @@ -193,6 +199,7 @@ func (d *LinuxDeviceManager) attemptFindOSTree(dir string, partition *snapshot.P
}

if !info.IsDir() {
log.Warn().Str("device", partition.Name).Msg("ostree is not a directory")
return false
}

Expand All @@ -209,6 +216,7 @@ func (d *LinuxDeviceManager) attemptFindOSTree(dir string, partition *snapshot.P
}

if len(matches) == 0 {
log.Debug().Str("device", partition.Name).Msg("no ostree matches")
return false
} else if len(matches) > 1 {
log.Warn().Str("device", partition.Name).Msg("multiple ostree matches")
Expand Down
2 changes: 1 addition & 1 deletion providers/os/connection/snapshot/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (i PartitionInfo) RootDir() string {
return path.Join(i.MountPoint, i.bind)
}

func (i PartitionInfo) SetBind(bind string) PartitionInfo {
func (i *PartitionInfo) SetBind(bind string) *PartitionInfo {
i.bind = bind
return i
}
Loading