Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .github/dependabot.yaml

This file was deleted.

21 changes: 13 additions & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linters:
- goprintffuncname
- gosmopolitan
- govet
- forcetypeassert
- grouper
- importas
- ineffassign
Expand All @@ -47,6 +48,8 @@ linters:
- tagalign
- tagliatelle
- testableexamples
- thelper
- tparallel
- unconvert
- unused
- usestdlibvars
Expand All @@ -60,16 +63,18 @@ linters:
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$

settings:
revive:
rules:
- name: var-naming
disabled: true

formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
4 changes: 4 additions & 0 deletions .renovaterc.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>go-git/.github"]
}
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ WASIRUN_WRAPPER := $(CURDIR)/scripts/wasirun-wrapper
COVERAGE_REPORT := coverage.out
COVERAGE_MODE := count

GOLANGCI_VERSION ?= v2.1.6
# renovate: datasource=github-tags depName=golangci/golangci-lint
GOLANGCI_VERSION ?= v2.6.0
TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools)

GOLANGCI = $(TOOLS_BIN)/golangci-lint-$(GOLANGCI_VERSION)
Expand Down Expand Up @@ -50,3 +51,6 @@ ifneq ($(shell git status --porcelain --untracked-files=no),)
@git --no-pager diff
@exit 1
endif

lint-autofix: $(GOLANGCI) # Auto fix supported lint issues.
$(GOLANGCI) run --fix
9 changes: 9 additions & 0 deletions embedfs/embed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func TestOpen(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

fs := New(&testdataDir)

var got []byte
Expand Down Expand Up @@ -115,6 +117,7 @@ func TestOpenFileFlags(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fs := New(&testdataDir)

_, err := fs.OpenFile(tc.file, tc.flag, 0o700)
Expand Down Expand Up @@ -157,6 +160,7 @@ func TestStat(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fs := New(&testdataDir)

fi, err := fs.Stat(tc.name)
Expand Down Expand Up @@ -213,6 +217,7 @@ func TestReadDir(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fs := New(tc.fs)

fis, err := fs.ReadDir(tc.path)
Expand Down Expand Up @@ -296,6 +301,7 @@ func TestFileSeek(t *testing.T) {

for i, tc := range tests {
t.Run(fmt.Sprintf("#%d", i), func(t *testing.T) {
//nolint:tparallel
_, err = f.Seek(tc.seekOff, tc.seekWhence)
require.NoError(t, err)

Expand All @@ -309,6 +315,8 @@ func TestFileSeek(t *testing.T) {
}

func TestJoin(t *testing.T) {
t.Parallel()

tests := []struct {
name string
path []string
Expand Down Expand Up @@ -338,6 +346,7 @@ func TestJoin(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fs := New(&empty)

got := fs.Join(tc.path...)
Expand Down
39 changes: 33 additions & 6 deletions helper/chroot/chroot.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chroot

import (
"errors"
"io/fs"
"os"
"path/filepath"
Expand Down Expand Up @@ -126,7 +127,12 @@ func (fs *ChrootHelper) TempFile(dir, prefix string) (billy.File, error) {
return nil, err
}

f, err := fs.underlying.(billy.TempFile).TempFile(fullpath, prefix)
tf, ok := fs.underlying.(billy.TempFile)
if !ok {
return nil, errors.New("underlying fs does not implement billy.TempFile")
}

f, err := tf.TempFile(fullpath, prefix)
if err != nil {
return nil, err
}
Expand All @@ -140,7 +146,11 @@ func (fs *ChrootHelper) ReadDir(path string) ([]fs.DirEntry, error) {
return nil, err
}

return fs.underlying.(billy.Dir).ReadDir(fullpath)
d, ok := fs.underlying.(billy.Dir)
if !ok {
return nil, errors.New("underlying fs does not implement billy.Dir")
}
return d.ReadDir(fullpath)
}

func (fs *ChrootHelper) MkdirAll(filename string, perm fs.FileMode) error {
Expand All @@ -149,7 +159,11 @@ func (fs *ChrootHelper) MkdirAll(filename string, perm fs.FileMode) error {
return err
}

return fs.underlying.(billy.Dir).MkdirAll(fullpath, perm)
d, ok := fs.underlying.(billy.Dir)
if !ok {
return errors.New("underlying fs does not implement billy.Dir")
}
return d.MkdirAll(fullpath, perm)
}

func (fs *ChrootHelper) Lstat(filename string) (os.FileInfo, error) {
Expand All @@ -158,7 +172,11 @@ func (fs *ChrootHelper) Lstat(filename string) (os.FileInfo, error) {
return nil, err
}

return fs.underlying.(billy.Symlink).Lstat(fullpath)
sl, ok := fs.underlying.(billy.Symlink)
if !ok {
return nil, errors.New("underlying fs does not implement billy.Symlink")
}
return sl.Lstat(fullpath)
}

func (fs *ChrootHelper) Symlink(target, link string) error {
Expand All @@ -175,7 +193,11 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
return err
}

return fs.underlying.(billy.Symlink).Symlink(target, link)
sl, ok := fs.underlying.(billy.Symlink)
if !ok {
return errors.New("underlying fs does not implement billy.Symlink")
}
return sl.Symlink(target, link)
}

func (fs *ChrootHelper) Readlink(link string) (string, error) {
Expand All @@ -184,7 +206,12 @@ func (fs *ChrootHelper) Readlink(link string) (string, error) {
return "", err
}

target, err := fs.underlying.(billy.Symlink).Readlink(fullpath)
sl, ok := fs.underlying.(billy.Symlink)
if !ok {
return "", errors.New("underlying fs does not implement billy.Symlink")
}

target, err := sl.Readlink(fullpath)
if err != nil {
return "", err
}
Expand Down
13 changes: 7 additions & 6 deletions helper/chroot/chroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ func TestOpenFile(t *testing.T) {
m := &test.BasicMock{}

fs := New(m, "/foo")
f, err := fs.OpenFile("bar/qux", 42, 0777)
f, err := fs.OpenFile("bar/qux", 42, 0o777)
require.NoError(t, err)
assert.Equal(t, f.Name(), filepath.Join("bar", "qux"))

assert.Len(t, m.OpenFileArgs, 1)
assert.Equal(t, m.OpenFileArgs[0], [3]interface{}{"/foo/bar/qux", 42, os.FileMode(0777)})
assert.Equal(t, m.OpenFileArgs[0], [3]interface{}{"/foo/bar/qux", 42, os.FileMode(0o777)})
}

func TestOpenFileErrCrossedBoundary(t *testing.T) {
m := &test.BasicMock{}

fs := New(m, "/foo")
_, err := fs.OpenFile("../foo", 42, 0777)
_, err := fs.OpenFile("../foo", 42, 0o777)
assert.ErrorIs(t, err, billy.ErrCrossedBoundary)
}

Expand Down Expand Up @@ -218,18 +218,18 @@ func TestMkDirAll(t *testing.T) {
m := &test.DirMock{}

fs := New(m, "/foo")
err := fs.MkdirAll("bar", 0777)
err := fs.MkdirAll("bar", 0o777)
require.NoError(t, err)

assert.Len(t, m.MkdirAllArgs, 1)
assert.Equal(t, m.MkdirAllArgs[0], [2]interface{}{"/foo/bar", os.FileMode(0777)})
assert.Equal(t, m.MkdirAllArgs[0], [2]interface{}{"/foo/bar", os.FileMode(0o777)})
}

func TestMkdirAllErrCrossedBoundary(t *testing.T) {
m := &test.DirMock{}

fs := New(m, "/foo")
err := fs.MkdirAll("../foo", 0777)
err := fs.MkdirAll("../foo", 0o777)
assert.ErrorIs(t, err, billy.ErrCrossedBoundary)
}

Expand Down Expand Up @@ -353,6 +353,7 @@ func TestCapabilities(t *testing.T) {
}

func testCapabilities(t *testing.T, basic billy.Basic) {
t.Helper()
baseCapabilities := billy.Capabilities(basic)

fs := New(basic, "/foo")
Expand Down
10 changes: 6 additions & 4 deletions helper/iofs/iofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ type adapterFs struct {
}

// Type assertion that adapterFS implements the following interfaces:
var _ fs.FS = (*adapterFs)(nil)
var _ fs.ReadDirFS = (*adapterFs)(nil)
var _ fs.StatFS = (*adapterFs)(nil)
var _ fs.ReadFileFS = (*adapterFs)(nil)
var (
_ fs.FS = (*adapterFs)(nil)
_ fs.ReadDirFS = (*adapterFs)(nil)
_ fs.StatFS = (*adapterFs)(nil)
_ fs.ReadFileFS = (*adapterFs)(nil)
)

// TODO: implement fs.GlobFS, which will be a fair bit more code.

Expand Down
12 changes: 7 additions & 5 deletions helper/iofs/iofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

billyfs "github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/memfs"
"github.com/stretchr/testify/require"
)

type errorList interface {
Expand All @@ -30,7 +31,7 @@ func TestWithFSTest(t *testing.T) {
}
createdFiles := make([]string, 0, len(files))
for filename, contents := range files {
makeFile(memfs, t, filename, contents)
makeFile(t, memfs, filename, contents)
createdFiles = append(createdFiles, filename)
}

Expand All @@ -47,10 +48,11 @@ func TestWithFSTest(t *testing.T) {
func TestDeletes(t *testing.T) {
t.Parallel()
memfs := memfs.New()
iofs := New(memfs).(fs.ReadFileFS)
iofs, ok := New(memfs).(fs.ReadFileFS)
require.True(t, ok)

makeFile(memfs, t, "foo.txt", "hello, world")
makeFile(memfs, t, "deleted", "nothing to see")
makeFile(t, memfs, "foo.txt", "hello, world")
makeFile(t, memfs, "deleted", "nothing to see")

if _, err := iofs.ReadFile("nonexistent"); err == nil {
t.Errorf("expected error for nonexistent file")
Expand All @@ -73,7 +75,7 @@ func TestDeletes(t *testing.T) {
}
}

func makeFile(fs billyfs.Basic, t *testing.T, filename string, contents string) {
func makeFile(t *testing.T, fs billyfs.Basic, filename string, contents string) {
t.Helper()
file, err := fs.Create(filename)
if err != nil {
Expand Down
Loading