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:
Arthur Sengileyev
2024-07-23 16:24:48 +03:00
parent b005b13274
commit 71d6e2fbaf
2 changed files with 20 additions and 2 deletions

View File

@@ -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
}