Skip to content

Commit

Permalink
wine: handle non-absolute wineprefix, give prefix error on command start
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Mar 8, 2024
1 parent 3a5116a commit 76af944
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions wine/wine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ package wine

import (
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
)

var ErrWineNotFound = errors.New("wine64 not found in $PATH or wineroot")
var (
ErrWineNotFound = errors.New("wine64 not found in $PATH or wineroot")
ErrPrefixNotAbs = errors.New("prefix directory is not an absolute path")
)

// Prefix is a representation of a wineprefix, which is where
// WINE stores its data and is equivalent to a C:\ drive.
Expand All @@ -36,19 +38,13 @@ func (p Prefix) String() string {
//
// dir must be an absolute path and has correct permissions
// to modify.
func New(dir string, root string) (*Prefix, error) {
// Always ensure its created, wine will complain if the root
// directory doesnt exist
if err := os.MkdirAll(dir, 0o755); err != nil {
return nil, fmt.Errorf("create prefix: %s", err)
}

func New(dir string, root string) *Prefix {
return &Prefix{
Root: root,
Stderr: os.Stderr,
Stdout: os.Stdout,
dir: dir,
}, nil
}
}

// Dir returns the directory of the Prefix.
Expand Down Expand Up @@ -83,6 +79,17 @@ func (p *Prefix) Wine(exe string, arg ...string) *Cmd {
cmd.Err = ErrWineNotFound
}

// Always ensure its created, wine will complain if the root
// directory doesnt exist
if err := os.MkdirAll(p.dir, 0o755); err != nil {
cmd.Err = err
}

// Wine requires a absolute path for the wineprefix
if !filepath.IsAbs(p.dir) {
cmd.Err = ErrPrefixNotAbs
}

if cmd.Args[0] == "ulwgl-run" {
cmd.Env = append(cmd.Environ(), "PROTON_VERB=runinprefix")
}
Expand Down

0 comments on commit 76af944

Please sign in to comment.