Skip to content

Commit

Permalink
shared/cliconfig: Handle incus-user
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 6, 2023
1 parent a69360e commit 0c753a0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion shared/cliconfig/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/pem"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

Expand Down Expand Up @@ -72,7 +73,28 @@ func (c *Config) GetInstanceServer(name string) (incus.InstanceServer, error) {

// Unix socket
if strings.HasPrefix(remote.Addr, "unix:") {
d, err := incus.ConnectIncusUnix(strings.TrimPrefix(strings.TrimPrefix(remote.Addr, "unix:"), "//"), args)
unixPath := remote.Addr
if unixPath == "unix://" {
// Handle unix socket path overrides.
unixPath = os.Getenv("INCUS_SOCKET")
if unixPath == "" {
incusDir := os.Getenv("INCUS_DIR")
if incusDir == "" {
incusDir = "/var/lib/incus/"
}

unixPath = filepath.Join(incusDir, "unix.socket")
userUnixPath := filepath.Join(incusDir, "unix.socket.user")
if !util.PathIsWritable(unixPath) && util.PathIsWritable(userUnixPath) {
// Handle the use of incus-user.
unixPath = userUnixPath
}
}
} else {
unixPath = strings.TrimPrefix(strings.TrimPrefix(remote.Addr, "unix:"), "//")
}

d, err := incus.ConnectIncusUnix(unixPath, args)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0c753a0

Please sign in to comment.