diff options
author | Brent Baude <bbaude@redhat.com> | 2022-03-31 16:11:04 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2022-04-05 13:14:28 -0500 |
commit | 9c72ea343435e502753bea9cfb0611cbc5dc91c1 (patch) | |
tree | 1104dd8e0857947481fc8b72d6df5463fb0cc5de /pkg/machine/qemu/config.go | |
parent | 5e821f7339bcfe7b653a2867c7637527d29efd79 (diff) | |
download | podman-9c72ea343435e502753bea9cfb0611cbc5dc91c1.tar.gz podman-9c72ea343435e502753bea9cfb0611cbc5dc91c1.tar.bz2 podman-9c72ea343435e502753bea9cfb0611cbc5dc91c1.zip |
machine refactor 3: add symlinks for sockets
to avoid errors on macos, we use symlinks to long socket names.
Fixes: #12751
Fixes: #13609
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 | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go index 3d1032fba..4d4e3a6c1 100644 --- a/pkg/machine/qemu/config.go +++ b/pkg/machine/qemu/config.go @@ -7,6 +7,7 @@ import ( "errors" "io/ioutil" "os" + "path/filepath" "time" "github.com/sirupsen/logrus" @@ -20,6 +21,9 @@ const ( Next string = "next" // Stable FCOS stream Stable string = "stable" + + // Max length of fully qualified socket path + maxSocketPathLength int = 103 ) type Provider struct{} @@ -197,8 +201,27 @@ func NewMachineFile(path string, symlink *string) (*MachineFile, error) { if symlink != nil && len(*symlink) < 1 { return nil, errors.New("invalid symlink path") } - return &MachineFile{ - Path: path, - Symlink: symlink, - }, nil + mf := MachineFile{Path: path} + if symlink != nil && len(path) > maxSocketPathLength { + if err := mf.makeSymlink(symlink); err != nil && !errors.Is(err, os.ErrExist) { + return nil, err + } + } + return &mf, nil +} + +// makeSymlink for macOS creates a symlink in $HOME/.podman/ +// for a machinefile like a socket +func (m *MachineFile) makeSymlink(symlink *string) error { + homedir, err := os.UserHomeDir() + if err != nil { + return err + } + sl := filepath.Join(homedir, ".podman", *symlink) + // make the symlink dir and throw away if it already exists + if err := os.MkdirAll(filepath.Dir(sl), 0700); err != nil && !errors.Is(err, os.ErrNotExist) { + return err + } + m.Symlink = &sl + return os.Symlink(m.Path, sl) } |