Skip to content

Commit

Permalink
appease unparam
Browse files Browse the repository at this point in the history
The testExpr method had some leftover unused parameters
from a refactor some time ago.

While here, replace os.FileInfo with fs.FileInfo,
since the former is now an alias for the latter.
  • Loading branch information
mvdan committed Oct 7, 2023
1 parent 08cb48c commit 1813dde
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Config struct {

// ReadDir is used for file path globbing. If nil, globbing is disabled.
// Use ioutil.ReadDir to use the filesystem directly.
ReadDir func(string) ([]os.FileInfo, error)
ReadDir func(string) ([]fs.FileInfo, error)

// GlobStar corresponds to the shell option that allows globbing with
// "**".
Expand Down
4 changes: 2 additions & 2 deletions fileutil/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (

// ConfIfShebang describes files which might be shell scripts, depending
// on the shebang line in the file's contents. Since CouldBeScript only
// works on os.FileInfo, the answer in this case can't be final.
// works on fs.FileInfo, the answer in this case can't be final.
ConfIfShebang

// ConfIsScript describes files which are definitely shell scripts,
Expand All @@ -61,7 +61,7 @@ const (
// CouldBeScript is a shortcut for CouldBeScript2(fs.FileInfoToDirEntry(info)).
//
// Deprecated: prefer CouldBeScript2, which usually requires fewer syscalls.
func CouldBeScript(info os.FileInfo) ScriptConfidence {
func CouldBeScript(info fs.FileInfo) ScriptConfidence {
return CouldBeScript2(fs.FileInfoToDirEntry(info))
}

Expand Down
9 changes: 5 additions & 4 deletions interp/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"io"
"io/fs"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -312,23 +313,23 @@ func DefaultOpenHandler() OpenHandlerFunc {
// shell globbing, if enabled.
//
// TODO(v4): if this is kept in v4, it most likely needs to use [io/fs.DirEntry] for efficiency
type ReadDirHandlerFunc func(ctx context.Context, path string) ([]os.FileInfo, error)
type ReadDirHandlerFunc func(ctx context.Context, path string) ([]fs.FileInfo, error)

// DefaultReadDirHandler returns the [ReadDirHandlerFunc] used by default.
// It makes use of [ioutil.ReadDir].
func DefaultReadDirHandler() ReadDirHandlerFunc {
return func(ctx context.Context, path string) ([]os.FileInfo, error) {
return func(ctx context.Context, path string) ([]fs.FileInfo, error) {
return ioutil.ReadDir(path)
}
}

// StatHandlerFunc is a handler which gets a file's information.
type StatHandlerFunc func(ctx context.Context, name string, followSymlinks bool) (os.FileInfo, error)
type StatHandlerFunc func(ctx context.Context, name string, followSymlinks bool) (fs.FileInfo, error)

// DefaultStatHandler returns the [StatHandlerFunc] used by default.
// It makes use of [os.Stat] and [os.Lstat], depending on followSymlinks.
func DefaultStatHandler() StatHandlerFunc {
return func(ctx context.Context, path string, followSymlinks bool) (os.FileInfo, error) {
return func(ctx context.Context, path string, followSymlinks bool) (fs.FileInfo, error) {
if !followSymlinks {
return os.Lstat(path)
} else {
Expand Down
3 changes: 2 additions & 1 deletion interp/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io"
"io/fs"
"os"
"runtime"
"strconv"
Expand Down Expand Up @@ -47,7 +48,7 @@ func blocklistNondevOpen(ctx context.Context, path string, flags int, mode os.Fi
return testOpenHandler(ctx, path, flags, mode)
}

func blocklistGlob(ctx context.Context, path string) ([]os.FileInfo, error) {
func blocklistGlob(ctx context.Context, path string) ([]fs.FileInfo, error) {
return nil, fmt.Errorf("blocklisted: glob")
}

Expand Down
7 changes: 4 additions & 3 deletions interp/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"math"
"math/rand"
"os"
Expand Down Expand Up @@ -157,7 +158,7 @@ func (r *Runner) updateExpandOpts() {
if r.opts[optNoGlob] {
r.ecfg.ReadDir = nil
} else {
r.ecfg.ReadDir = func(s string) ([]os.FileInfo, error) {
r.ecfg.ReadDir = func(s string) ([]fs.FileInfo, error) {
return r.readDirHandler(r.handlerCtx(context.Background()), s)
}
}
Expand Down Expand Up @@ -982,12 +983,12 @@ func (r *Runner) open(ctx context.Context, path string, flags int, mode os.FileM
return f, err
}

func (r *Runner) stat(ctx context.Context, name string) (os.FileInfo, error) {
func (r *Runner) stat(ctx context.Context, name string) (fs.FileInfo, error) {
path := absPath(r.Dir, name)
return r.statHandler(ctx, path, true)
}

func (r *Runner) lstat(ctx context.Context, name string) (os.FileInfo, error) {
func (r *Runner) lstat(ctx context.Context, name string) (fs.FileInfo, error) {
path := absPath(r.Dir, name)
return r.statHandler(ctx, path, false)
}
12 changes: 6 additions & 6 deletions syntax/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ func (p *Parser) testClause(s *Stmt) {
if _, ok := p.gotRsrv("]]"); ok || p.tok == _EOF {
p.posErr(tc.Left, "test clause requires at least one expression")
}
tc.X = p.testExpr(dblLeftBrack, tc.Left, false)
tc.X = p.testExpr(false)
if tc.X == nil {
p.followErrExp(tc.Left, "[[")
}
Expand All @@ -2160,13 +2160,13 @@ func (p *Parser) testClause(s *Stmt) {
s.Cmd = tc
}

func (p *Parser) testExpr(ftok token, fpos Pos, pastAndOr bool) TestExpr {
func (p *Parser) testExpr(pastAndOr bool) TestExpr {
p.got(_Newl)
var left TestExpr
if pastAndOr {
left = p.testExprBase()
} else {
left = p.testExpr(ftok, fpos, true)
left = p.testExpr(true)
}
if left == nil {
return left
Expand Down Expand Up @@ -2200,7 +2200,7 @@ func (p *Parser) testExpr(ftok token, fpos Pos, pastAndOr bool) TestExpr {
switch b.Op {
case AndTest, OrTest:
p.next()
if b.Y = p.testExpr(token(b.Op), b.OpPos, false); b.Y == nil {
if b.Y = p.testExpr(false); b.Y == nil {
p.followErrExp(b.OpPos, b.Op.String())
}
case TsReMatch:
Expand Down Expand Up @@ -2246,7 +2246,7 @@ func (p *Parser) testExprBase() TestExpr {
case exclMark:
u := &UnaryTest{OpPos: p.pos, Op: TsNot}
p.next()
if u.X = p.testExpr(token(u.Op), u.OpPos, false); u.X == nil {
if u.X = p.testExpr(false); u.X == nil {
p.followErrExp(u.OpPos, u.Op.String())
}
return u
Expand All @@ -2261,7 +2261,7 @@ func (p *Parser) testExprBase() TestExpr {
case leftParen:
pe := &ParenTest{Lparen: p.pos}
p.next()
if pe.X = p.testExpr(leftParen, pe.Lparen, false); pe.X == nil {
if pe.X = p.testExpr(false); pe.X == nil {
p.followErrExp(pe.Lparen, "(")
}
pe.Rparen = p.matched(pe.Lparen, leftParen, rightParen)
Expand Down

0 comments on commit 1813dde

Please sign in to comment.