1// Copyright (c) 2017, Andrey Nering <andrey.nering@gmail.com>
2// See LICENSE for licensing information
3
4//go:build !unix
5
6package interp
7
8import (
9 "context"
10 "fmt"
11
12 "mvdan.cc/sh/v3/syntax"
13)
14
15func mkfifo(path string, mode uint32) error {
16 return fmt.Errorf("unsupported")
17}
18
19// access attempts to emulate [unix.Access] on Windows.
20// Windows seems to have a different system of permissions than Unix,
21// so for now just rely on what [io/fs.FileInfo] gives us.
22func (r *Runner) access(ctx context.Context, path string, mode uint32) error {
23 info, err := r.lstat(ctx, path)
24 if err != nil {
25 return err
26 }
27 m := info.Mode()
28 switch mode {
29 case access_R_OK:
30 if m&0o400 == 0 {
31 return fmt.Errorf("file is not readable")
32 }
33 case access_W_OK:
34 if m&0o200 == 0 {
35 return fmt.Errorf("file is not writable")
36 }
37 case access_X_OK:
38 if m&0o100 == 0 {
39 return fmt.Errorf("file is not executable")
40 }
41 }
42 return nil
43}
44
45// unTestOwnOrGrp panics. Under Unix, it implements the -O and -G unary tests,
46// but under Windows, it's unclear how to implement those tests, since Windows
47// doesn't have the concept of a file owner, just ACLs, and it's unclear how
48// to map the one to the other.
49func (r *Runner) unTestOwnOrGrp(ctx context.Context, op syntax.UnTestOperator, x string) bool {
50 panic(fmt.Sprintf("unhandled unary test op: %v", op))
51}
52
53// waitStatus is a no-op on plan9 and windows.
54type waitStatus struct{}
55
56func (waitStatus) Signaled() bool { return false }
57func (waitStatus) Signal() int { return 0 }