Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump module to v6 #107

Merged
merged 4 commits into from
Jan 25, 2025
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# go-billy [![GoDoc](https://godoc.org/gopkg.in/go-git/go-billy.v5?status.svg)](https://pkg.go.dev/github.com/go-git/go-billy/v5) [![Test](https://github.com/go-git/go-billy/workflows/Test/badge.svg)](https://github.com/go-git/go-billy/actions?query=workflow%3ATest)
# go-billy [![GoDoc](https://godoc.org/gopkg.in/go-git/go-billy.v6?status.svg)](https://pkg.go.dev/github.com/go-git/go-billy/v6) [![Test](https://github.com/go-git/go-billy/workflows/Test/badge.svg)](https://github.com/go-git/go-billy/actions?query=workflow%3ATest)

The missing interface filesystem abstraction for Go.
Billy implements an interface based on the `os` standard library, allowing to develop applications without dependency on the underlying storage. Makes it virtually free to implement mocks and testing over filesystem operations.
Expand All @@ -8,14 +8,14 @@ Billy was born as part of [go-git/go-git](https://github.com/go-git/go-git) proj
## Installation

```go
import "github.com/go-git/go-billy/v5" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/go-git/go-billy/v6" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/go-git/go-billy" // with go modules disabled
```

## Usage

Billy exposes filesystems using the
[`Filesystem` interface](https://pkg.go.dev/github.com/go-git/go-billy/v5?tab=doc#Filesystem).
[`Filesystem` interface](https://pkg.go.dev/github.com/go-git/go-billy/v6?tab=doc#Filesystem).
Each filesystem implementation gives you a `New` method, whose arguments depend on
the implementation itself, that returns a new `Filesystem`.

Expand Down
21 changes: 10 additions & 11 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package billy
import (
"errors"
"io"
"os"
"io/fs"
"time"
)

Expand Down Expand Up @@ -72,9 +72,9 @@ type Basic interface {
// instead. It opens the named file with specified flag (O_RDONLY etc.) and
// perm, (0666 etc.) if applicable. If successful, methods on the returned
// File can be used for I/O.
OpenFile(filename string, flag int, perm os.FileMode) (File, error)
OpenFile(filename string, flag int, perm fs.FileMode) (File, error)
// Stat returns a FileInfo describing the named file.
Stat(filename string) (os.FileInfo, error)
Stat(filename string) (fs.FileInfo, error)
// Rename renames (moves) oldpath to newpath. If newpath already exists and
// is not a directory, Rename replaces it. OS-specific restrictions may
// apply when oldpath and newpath are in different directories.
Expand Down Expand Up @@ -105,12 +105,12 @@ type TempFile interface {
type Dir interface {
// ReadDir reads the directory named by dirname and returns a list of
// directory entries sorted by filename.
ReadDir(path string) ([]os.FileInfo, error)
ReadDir(path string) ([]fs.FileInfo, error)
// MkdirAll creates a directory named path, along with any necessary
// parents, and returns nil, or else returns an error. The permission bits
// perm are used for all directories that MkdirAll creates. If path is/
// already a directory, MkdirAll does nothing and returns nil.
MkdirAll(filename string, perm os.FileMode) error
MkdirAll(filename string, perm fs.FileMode) error
}

// Symlink abstract the symlink related operations in a storage-agnostic
Expand All @@ -119,7 +119,7 @@ type Symlink interface {
// Lstat returns a FileInfo describing the named file. If the file is a
// symbolic link, the returned FileInfo describes the symbolic link. Lstat
// makes no attempt to follow the link.
Lstat(filename string) (os.FileInfo, error)
Lstat(filename string) (fs.FileInfo, error)
// Symlink creates a symbolic-link from link to target. target may be an
// absolute or relative path, and need not refer to an existing node.
// Parent directories of link are created as necessary.
Expand All @@ -133,7 +133,7 @@ type Symlink interface {
type Change interface {
// Chmod changes the mode of the named file to mode. If the file is a
// symbolic link, it changes the mode of the link's target.
Chmod(name string, mode os.FileMode) error
Chmod(name string, mode fs.FileMode) error
// Lchown changes the numeric uid and gid of the named file. If the file is
// a symbolic link, it changes the uid and gid of the link itself.
Lchown(name string, uid, gid int) error
Expand Down Expand Up @@ -161,15 +161,14 @@ type Chroot interface {

// File represent a file, being a subset of the os.File
type File interface {
fs.File

// Name returns the name of the file as presented to Open.
Name() string
io.Writer
// TODO: Add io.WriterAt for v6
// io.WriterAt
io.Reader
io.WriterAt
io.ReaderAt
io.Seeker
io.Closer
// Lock locks the file like e.g. flock. It protects against access from
// other processes.
Lock() error
Expand Down
4 changes: 2 additions & 2 deletions fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package billy_test
import (
"testing"

. "github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/internal/test"
. "github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/internal/test"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/go-git/go-billy/v5
module github.com/go-git/go-billy/v6

// go-git supports the last 3 stable Go versions.
go 1.21
Expand Down
9 changes: 5 additions & 4 deletions helper/chroot/chroot.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package chroot

import (
"io/fs"
"os"
"path/filepath"
"strings"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/helper/polyfill"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/helper/polyfill"
)

// ChrootHelper is a helper to implement billy.Chroot.
Expand Down Expand Up @@ -68,7 +69,7 @@ func (fs *ChrootHelper) Open(filename string) (billy.File, error) {
return newFile(fs, f, filename), nil
}

func (fs *ChrootHelper) OpenFile(filename string, flag int, mode os.FileMode) (billy.File, error) {
func (fs *ChrootHelper) OpenFile(filename string, flag int, mode fs.FileMode) (billy.File, error) {
fullpath, err := fs.underlyingPath(filename)
if err != nil {
return nil, err
Expand Down Expand Up @@ -142,7 +143,7 @@ func (fs *ChrootHelper) ReadDir(path string) ([]os.FileInfo, error) {
return fs.underlying.(billy.Dir).ReadDir(fullpath)
}

func (fs *ChrootHelper) MkdirAll(filename string, perm os.FileMode) error {
func (fs *ChrootHelper) MkdirAll(filename string, perm fs.FileMode) error {
fullpath, err := fs.underlyingPath(filename)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions helper/chroot/chroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"path/filepath"
"testing"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/internal/test"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/internal/test"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions helper/iofs/iofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"io/fs"
"path/filepath"

billyfs "github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/helper/polyfill"
billyfs "github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/helper/polyfill"
)

// Wrap adapts a billy.Filesystem to a io.fs.FS.
Expand Down
4 changes: 2 additions & 2 deletions helper/iofs/iofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"testing/fstest"

billyfs "github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/memfs"
billyfs "github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/memfs"
)

type errorList interface {
Expand Down
9 changes: 5 additions & 4 deletions helper/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package mount

import (
"io"
"io/fs"
"os"
"path/filepath"
"strings"

"fmt"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/helper/polyfill"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/helper/polyfill"
)

var separator = string(filepath.Separator)
Expand Down Expand Up @@ -53,7 +54,7 @@ func (h *Mount) Open(path string) (billy.File, error) {
return wrapFile(f, path), err
}

func (h *Mount) OpenFile(path string, flag int, mode os.FileMode) (billy.File, error) {
func (h *Mount) OpenFile(path string, flag int, mode fs.FileMode) (billy.File, error) {
fs, fullpath := h.getBasicAndPath(path)
if fullpath == "." {
return nil, os.ErrInvalid
Expand Down Expand Up @@ -118,7 +119,7 @@ func (h *Mount) ReadDir(path string) ([]os.FileInfo, error) {
return fs.ReadDir(fullpath)
}

func (h *Mount) MkdirAll(filename string, perm os.FileMode) error {
func (h *Mount) MkdirAll(filename string, perm fs.FileMode) error {
fs, fullpath, err := h.getDirAndPath(filename)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions helper/mount/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"path/filepath"
"testing"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/internal/test"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-billy/v5/util"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/internal/test"
"github.com/go-git/go-billy/v6/memfs"
"github.com/go-git/go-billy/v6/util"
"github.com/stretchr/testify/assert"
)

Expand Down
5 changes: 3 additions & 2 deletions helper/polyfill/polyfill.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package polyfill

import (
"io/fs"
"os"
"path/filepath"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v6"
)

// Polyfill is a helper that implements all missing method from billy.Filesystem.
Expand Down Expand Up @@ -47,7 +48,7 @@ func (h *Polyfill) ReadDir(path string) ([]os.FileInfo, error) {
return h.Basic.(billy.Dir).ReadDir(path)
}

func (h *Polyfill) MkdirAll(filename string, perm os.FileMode) error {
func (h *Polyfill) MkdirAll(filename string, perm fs.FileMode) error {
if !h.c.dir {
return billy.ErrNotSupported
}
Expand Down
4 changes: 2 additions & 2 deletions helper/polyfill/polyfill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"path/filepath"
"testing"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/internal/test"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/internal/test"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions helper/temporal/temporal.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package temporal

import (
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/util"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/util"
)

// Temporal is a helper that implements billy.TempFile over any filesystem.
Expand Down
2 changes: 1 addition & 1 deletion helper/temporal/temporal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"testing"

"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-billy/v6/memfs"
"github.com/stretchr/testify/assert"
)

Expand Down
11 changes: 8 additions & 3 deletions internal/test/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package test

import (
"bytes"
"io/fs"
"os"
"path"
"path/filepath"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v6"
)

type BasicMock struct {
Expand All @@ -29,7 +30,7 @@ func (fs *BasicMock) Open(filename string) (billy.File, error) {
return &FileMock{name: filename}, nil
}

func (fs *BasicMock) OpenFile(filename string, flag int, mode os.FileMode) (billy.File, error) {
func (fs *BasicMock) OpenFile(filename string, flag int, mode fs.FileMode) (billy.File, error) {
fs.OpenFileArgs = append(fs.OpenFileArgs, [3]interface{}{filename, flag, mode})
return &FileMock{name: filename}, nil
}
Expand Down Expand Up @@ -75,7 +76,7 @@ func (fs *DirMock) ReadDir(path string) ([]os.FileInfo, error) {
return nil, nil
}

func (fs *DirMock) MkdirAll(filename string, perm os.FileMode) error {
func (fs *DirMock) MkdirAll(filename string, perm fs.FileMode) error {
fs.MkdirAllArgs = append(fs.MkdirAllArgs, [2]interface{}{filename, perm})
return nil
}
Expand Down Expand Up @@ -135,6 +136,10 @@ func (*FileMock) Unlock() error {
return nil
}

func (*FileMock) Stat() (fs.FileInfo, error) {
return nil, nil
}

func (*FileMock) Truncate(size int64) error {
return nil
}
Expand Down
19 changes: 10 additions & 9 deletions memfs/memory.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// Package memfs provides a billy filesystem base on memory.
package memfs // import "github.com/go-git/go-billy/v5/memfs"
package memfs // import "github.com/go-git/go-billy/v6/memfs"

import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"syscall"
"time"

"github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/helper/chroot"
"github.com/go-git/go-billy/v5/util"
"github.com/go-git/go-billy/v6"
"github.com/go-git/go-billy/v6/helper/chroot"
"github.com/go-git/go-billy/v6/util"
)

const separator = filepath.Separator
Expand Down Expand Up @@ -43,7 +44,7 @@ func (fs *Memory) Open(filename string) (billy.File, error) {
return fs.OpenFile(filename, os.O_RDONLY, 0)
}

func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) {
func (fs *Memory) OpenFile(filename string, flag int, perm fs.FileMode) (billy.File, error) {
f, has := fs.s.Get(filename)
if !has {
if !isCreate(flag) {
Expand Down Expand Up @@ -154,7 +155,7 @@ func (fs *Memory) ReadDir(path string) ([]os.FileInfo, error) {
return entries, nil
}

func (fs *Memory) MkdirAll(path string, perm os.FileMode) error {
func (fs *Memory) MkdirAll(path string, perm fs.FileMode) error {
_, err := fs.s.New(path, perm|os.ModeDir, 0)
return err
}
Expand Down Expand Up @@ -318,7 +319,7 @@ func (f *file) Truncate(size int64) error {
return nil
}

func (f *file) Duplicate(filename string, mode os.FileMode, flag int) billy.File {
func (f *file) Duplicate(filename string, mode fs.FileMode, flag int) billy.File {
new := &file{
name: filename,
content: f.content,
Expand Down Expand Up @@ -372,7 +373,7 @@ func (fi *fileInfo) Size() int64 {
return int64(fi.size)
}

func (fi *fileInfo) Mode() os.FileMode {
func (fi *fileInfo) Mode() fs.FileMode {
return fi.mode
}

Expand Down Expand Up @@ -424,6 +425,6 @@ func isWriteOnly(flag int) bool {
return flag&os.O_WRONLY != 0
}

func isSymlink(m os.FileMode) bool {
func isSymlink(m fs.FileMode) bool {
return m&os.ModeSymlink != 0
}
Loading
Loading