diff options
author | Brent Baude <bbaude@redhat.com> | 2022-03-29 15:04:35 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2022-03-30 09:22:40 -0500 |
commit | a06df4fc1aca86ddc4007f4957b53509e8d39e19 (patch) | |
tree | 48a2dd58653d11813814effd38f2d0bb47035b52 /pkg/machine/qemu/config.go | |
parent | ff8834f0232f128b781ec23d66a5676da0670847 (diff) | |
download | podman-a06df4fc1aca86ddc4007f4957b53509e8d39e19.tar.gz podman-a06df4fc1aca86ddc4007f4957b53509e8d39e19.tar.bz2 podman-a06df4fc1aca86ddc4007f4957b53509e8d39e19.zip |
Machine refactor part 2
This PR further implements a more structured approach to handling the
files needed by machine. More files are now made as MachineFile which
can then have a symlink (using a shorter path) to them. Also added Set
and Get methods for many of the files.
The next part of the refactor will implement the use of symlinks on
MacOS.
Signed-off-by: Brent Baude <bbaude@redhat.com>
[NO NEW TESTS NEEDED]
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/machine/qemu/config.go')
-rw-r--r-- | pkg/machine/qemu/config.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 05a1d74d3..3d1032fba 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -5,6 +5,7 @@ package qemu import ( "errors" + "io/ioutil" "os" "time" @@ -59,6 +60,8 @@ type MachineVMV1 struct { } type MachineVM struct { + // ConfigPath is the path to the configuration file + ConfigPath MachineFile // The command line representation of the qemu command CmdLine []string // HostUser contains info about host user @@ -83,11 +86,11 @@ type MachineVM struct { // ImageConfig describes the bootable image for the VM type ImageConfig struct { - IgnitionFilePath string + IgnitionFilePath MachineFile // ImageStream is the update stream for the image ImageStream string // ImagePath is the fq path to - ImagePath string + ImagePath MachineFile } // HostUser describes the host user @@ -171,11 +174,19 @@ func (m *MachineFile) GetPath() string { // the actual path func (m *MachineFile) Delete() error { if m.Symlink != nil { - if err := os.Remove(*m.Symlink); err != nil { + if err := os.Remove(*m.Symlink); err != nil && !errors.Is(err, os.ErrNotExist) { logrus.Errorf("unable to remove symlink %q", *m.Symlink) } } - return os.Remove(m.Path) + if err := os.Remove(m.Path); err != nil && !errors.Is(err, os.ErrNotExist) { + return err + } + return nil +} + +// Read the contents of a given file and return in []bytes +func (m *MachineFile) Read() ([]byte, error) { + return ioutil.ReadFile(m.GetPath()) } // NewMachineFile is a constructor for MachineFile |