Skip to content

Commit 0ffbf59

Browse files
committed
Use fs.File as base for File interface
This is a stepping stone towards making go-billy more io/fs friendly. Signed-off-by: Paulo Gomes <[email protected]>
1 parent 84be677 commit 0ffbf59

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

fs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package billy
33
import (
44
"errors"
55
"io"
6+
"io/fs"
67
"os"
78
"time"
89
)
@@ -161,15 +162,15 @@ type Chroot interface {
161162

162163
// File represent a file, being a subset of the os.File
163164
type File interface {
165+
fs.File
166+
164167
// Name returns the name of the file as presented to Open.
165168
Name() string
166169
io.Writer
167-
// TODO: Add io.WriterAt for v6
170+
// TODO: Add io.WriterAt for v6
168171
// io.WriterAt
169-
io.Reader
170172
io.ReaderAt
171173
io.Seeker
172-
io.Closer
173174
// Lock locks the file like e.g. flock. It protects against access from
174175
// other processes.
175176
Lock() error

internal/test/mock.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"bytes"
5+
"io/fs"
56
"os"
67
"path"
78
"path/filepath"
@@ -135,6 +136,10 @@ func (*FileMock) Unlock() error {
135136
return nil
136137
}
137138

139+
func (*FileMock) Stat() (fs.FileInfo, error) {
140+
return nil, nil
141+
}
142+
138143
func (*FileMock) Truncate(size int64) error {
139144
return nil
140145
}

memfs/memory_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package memfs
33
import (
44
"fmt"
55
"io"
6+
"io/fs"
67
"os"
78
"runtime"
89
"testing"
@@ -14,6 +15,8 @@ import (
1415
"github.com/stretchr/testify/require"
1516
)
1617

18+
var _ fs.File = &file{}
19+
1720
func TestRootExists(t *testing.T) {
1821
fs := New()
1922
f, err := fs.Stat("/")

osfs/os_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
package osfs
55

66
import (
7+
"io/fs"
78
"reflect"
89
"testing"
910
)
1011

12+
var _ fs.File = &file{}
13+
1114
func TestDefault(t *testing.T) {
1215
want := &ChrootOS{}
1316
got := Default

0 commit comments

Comments
 (0)