mirror of
https://github.com/containers/podman.git
synced 2025-12-02 02:58:03 +08:00
Add utility to convert VMFile to URL for UNIX sockets
This adds generic utility to convert file system path into URL structure. Instead of string manipulation it uses URL parsing and building routines. Appending absolute path to `unix:///` URL out of the box correctly handles URL format on Windows platform, where filepath should be prepended by additional `/` before drive letter. Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -319,11 +318,15 @@ func (q *QEMUStubber) StartNetworking(mc *vmconfigs.MachineConfig, cmd *gvproxy.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
socketURL, err := sockets.ToUnixURL(gvProxySock)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// make sure it does not exist before gvproxy is called
|
||||
if err := gvProxySock.Delete(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
cmd.AddQemuSocket(fmt.Sprintf("unix://%s", filepath.ToSlash(gvProxySock.GetPath())))
|
||||
cmd.AddQemuSocket(socketURL.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@@ -110,3 +111,17 @@ func WaitForSocketWithBackoffs(maxBackoffs int, backoff time.Duration, socketPat
|
||||
}
|
||||
return fmt.Errorf("unable to connect to %q socket at %q", name, socketPath)
|
||||
}
|
||||
|
||||
// ToUnixURL converts `socketLoc` into URL representation
|
||||
func ToUnixURL(socketLoc *define.VMFile) (*url.URL, error) {
|
||||
p := socketLoc.GetPath()
|
||||
if !filepath.IsAbs(p) {
|
||||
return nil, fmt.Errorf("socket path must be absolute %q", p)
|
||||
}
|
||||
s, err := url.Parse("unix:///")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s = s.JoinPath(filepath.ToSlash(p))
|
||||
return s, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user