X Tutup
Skip to content

Commit cd14227

Browse files
committed
fix wine causing launcht to fail if .exe couldn't be found with {{EXT}} template action
1 parent 7cabcc0 commit cd14227

File tree

3 files changed

+143
-5
lines changed

3 files changed

+143
-5
lines changed

cmd/auditzip/auditzip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func Do(consumer *state.Consumer, file string, upstream bool) error {
261261

262262
actualSize, err := io.Copy(ioutil.Discard, rc)
263263
if err != nil {
264-
markError(path, err.Error())
264+
markError(path, "%s", err.Error())
265265
return nil
266266
}
267267

endpoints/launch/helpers.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package launch
22

33
import (
4-
"path/filepath"
5-
64
"crawshaw.io/sqlite"
75
validation "github.com/go-ozzo/ozzo-validation"
86
"github.com/itchio/butler/butlerd"
@@ -184,6 +182,10 @@ func getTargetsForHost(rc *butlerd.RequestContext,
184182
consumer.Opf("Seeking launch targets for host (%s)", host)
185183

186184
var targets []*butlerd.LaunchTarget
185+
nativeHost := host.Runtime == info.runtime && host.Wrapper == nil && host.RemoteLaunchName == ""
186+
actionsForHostCount := 0
187+
failedActionCount := 0
188+
var firstActionErr error
187189

188190
if appManifest == nil {
189191
consumer.Infof("No app manifest.")
@@ -192,7 +194,7 @@ func getTargetsForHost(rc *butlerd.RequestContext,
192194
if action.Path == "" {
193195
return action, nil
194196
}
195-
actionPath := filepath.Join(info.installFolder, action.Path)
197+
actionPath := action.ExpandPath(host.Runtime.Platform, info.installFolder)
196198
_, err := screw.Lstat(actionPath)
197199
if err != nil {
198200
consumer.Warnf("Could not stat (%s)", actionPath)
@@ -231,11 +233,17 @@ func getTargetsForHost(rc *butlerd.RequestContext,
231233
}
232234

233235
actions = actions.FilterByPlatform(host.Runtime.Platform)
236+
actionsForHostCount = len(actions)
234237

235238
for _, action := range actions {
236239
target, err := ActionToLaunchTarget(consumer, host, info.installFolder, action)
237240
if err != nil {
238-
return nil, err
241+
failedActionCount++
242+
if firstActionErr == nil {
243+
firstActionErr = err
244+
}
245+
consumer.Warnf("Could not resolve launch target for action '%s' on host %s: %v", action.Name, host, err)
246+
continue
239247
}
240248
targets = append(targets, target)
241249
consumer.Logf("%s", target.Strategy.String())
@@ -246,6 +254,13 @@ func getTargetsForHost(rc *butlerd.RequestContext,
246254
return targets, nil
247255
}
248256

257+
if nativeHost && actionsForHostCount > 0 && failedActionCount == actionsForHostCount {
258+
return nil, errors.Errorf(
259+
"failed to resolve %d/%d manifest actions for native host %s (first error: %v)",
260+
failedActionCount, actionsForHostCount, host, firstActionErr,
261+
)
262+
}
263+
249264
consumer.Infof("Filtering verdict for host %v", host)
250265
filterParams := dash.FilterParams{
251266
OS: host.Runtime.OS(),

endpoints/launch/helpers_test.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package launch
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
"testing"
8+
9+
"github.com/itchio/butler/butlerd"
10+
"github.com/itchio/butler/manager"
11+
"github.com/itchio/dash"
12+
"github.com/itchio/headway/state"
13+
"github.com/itchio/hush/manifest"
14+
"github.com/itchio/ox"
15+
)
16+
17+
func TestGetTargetsForHost_NativeAllManifestActionsFail(t *testing.T) {
18+
t.Parallel()
19+
20+
installFolder := t.TempDir()
21+
runtime := ox.Runtime{Platform: ox.PlatformLinux, Is64: true}
22+
23+
rc := &butlerd.RequestContext{Consumer: &state.Consumer{}}
24+
info := withInstallFolderInfo{
25+
installFolder: installFolder,
26+
runtime: runtime,
27+
}
28+
host := manager.Host{Runtime: runtime}
29+
30+
appManifest := &manifest.Manifest{
31+
Actions: manifest.Actions{
32+
{
33+
Name: "Default",
34+
Path: "Missing{{EXT}}",
35+
},
36+
},
37+
}
38+
39+
_, err := getTargetsForHost(rc, nil, appManifest, &dash.Verdict{}, info, host)
40+
if err == nil {
41+
t.Fatalf("expected error when all native manifest actions fail")
42+
}
43+
if !strings.Contains(err.Error(), "failed to resolve 1/1 manifest actions for native host") {
44+
t.Fatalf("expected native manifest failure error, got: %v", err)
45+
}
46+
}
47+
48+
func TestGetTargetsForHost_NonNativeAllManifestActionsFail(t *testing.T) {
49+
t.Parallel()
50+
51+
installFolder := t.TempDir()
52+
nativeRuntime := ox.Runtime{Platform: ox.PlatformLinux, Is64: true}
53+
wineRuntime := ox.Runtime{Platform: ox.PlatformWindows, Is64: false}
54+
55+
rc := &butlerd.RequestContext{Consumer: &state.Consumer{}}
56+
info := withInstallFolderInfo{
57+
installFolder: installFolder,
58+
runtime: nativeRuntime,
59+
}
60+
host := manager.Host{
61+
Runtime: wineRuntime,
62+
Wrapper: &manager.Wrapper{
63+
WrapperBinary: "wine",
64+
},
65+
}
66+
67+
appManifest := &manifest.Manifest{
68+
Actions: manifest.Actions{
69+
{
70+
Name: "Default",
71+
Path: "Missing{{EXT}}",
72+
},
73+
},
74+
}
75+
76+
targets, err := getTargetsForHost(rc, nil, appManifest, &dash.Verdict{}, info, host)
77+
if err != nil {
78+
t.Fatalf("expected no error for non-native host when all manifest actions fail, got: %v", err)
79+
}
80+
if len(targets) != 0 {
81+
t.Fatalf("expected no targets from empty fallback verdict, got %d", len(targets))
82+
}
83+
}
84+
85+
func TestGetTargetsForHost_NativePartialManifestResolution(t *testing.T) {
86+
t.Parallel()
87+
88+
installFolder := t.TempDir()
89+
runtime := ox.Runtime{Platform: ox.PlatformLinux, Is64: true}
90+
91+
rc := &butlerd.RequestContext{Consumer: &state.Consumer{}}
92+
info := withInstallFolderInfo{
93+
installFolder: installFolder,
94+
runtime: runtime,
95+
}
96+
host := manager.Host{Runtime: runtime}
97+
98+
validActionDir := filepath.Join(installFolder, "Sample Evil App")
99+
if err := os.MkdirAll(validActionDir, 0o755); err != nil {
100+
t.Fatalf("creating valid action dir: %v", err)
101+
}
102+
103+
appManifest := &manifest.Manifest{
104+
Actions: manifest.Actions{
105+
{
106+
Name: "Valid",
107+
Path: "Sample Evil App{{EXT}}",
108+
},
109+
{
110+
Name: "Missing",
111+
Path: "Missing{{EXT}}",
112+
},
113+
},
114+
}
115+
116+
targets, err := getTargetsForHost(rc, nil, appManifest, &dash.Verdict{}, info, host)
117+
if err != nil {
118+
t.Fatalf("expected no error when at least one native action resolves, got: %v", err)
119+
}
120+
if len(targets) == 0 {
121+
t.Fatalf("expected at least one resolved target")
122+
}
123+
}

0 commit comments

Comments
 (0)
X Tutup