Skip to content

Commit

Permalink
Merge pull request #50 from pjbgf/fix-sl
Browse files Browse the repository at this point in the history
General improvements to memfs
  • Loading branch information
pjbgf authored Apr 27, 2024
2 parents 72e8966 + 9a50ca8 commit 8453aa9
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 36 deletions.
15 changes: 15 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "build"

- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: "build"
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x,1.21.x]
go-version: [1.20.x,1.21.x,1.22.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Test
run: make test
8 changes: 4 additions & 4 deletions .github/workflows/test_js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.x,1.21.x]
go-version: [1.21.x,1.22.x]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
Expand All @@ -18,9 +21,6 @@ jobs:
go install github.com/agnivade/wasmbrowsertest@latest
mv $HOME/go/bin/wasmbrowsertest $HOME/go/bin/go_js_wasm_exec
- name: Checkout code
uses: actions/checkout@v3

- name: Test
run: go test -exec="$HOME/go/bin/go_js_wasm_exec" ./...
env:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test_wasip1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
go-version: [1.21.x,1.22.x]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
Expand All @@ -17,8 +20,5 @@ jobs:
run: |
go install github.com/stealthrocket/wasi-go/cmd/wasirun@latest
- name: Checkout code
uses: actions/checkout@v3

- name: Test
run: make wasitest
run: make wasitest
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
module github.com/go-git/go-billy/v5

// go-git supports the last 3 stable Go versions.
go 1.19
go 1.20

require (
github.com/cyphar/filepath-securejoin v0.2.4
github.com/onsi/gomega v1.27.10
github.com/stretchr/testify v1.9.0
golang.org/x/sys v0.18.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
Expand All @@ -17,9 +19,13 @@ github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
Expand Down
23 changes: 13 additions & 10 deletions memfs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (

const separator = filepath.Separator

// Memory a very convenient filesystem based on memory files
var errNotLink = errors.New("not a link")

// Memory a very convenient filesystem based on memory files.
type Memory struct {
s *storage

Expand Down Expand Up @@ -59,10 +61,9 @@ func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (billy.F
}

if target, isLink := fs.resolveLink(filename, f); isLink {
if target == filename {
return nil, os.ErrNotExist
if target != filename {
return fs.OpenFile(target, flag, perm)
}
return fs.OpenFile(target, flag, perm)
}
}

Expand All @@ -73,8 +74,6 @@ func (fs *Memory) OpenFile(filename string, flag int, perm os.FileMode) (billy.F
return f.Duplicate(filename, perm, flag), nil
}

var errNotLink = errors.New("not a link")

func (fs *Memory) resolveLink(fullpath string, f *file) (target string, isLink bool) {
if !isSymlink(f.mode) {
return fullpath, false
Expand Down Expand Up @@ -136,7 +135,9 @@ func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (fs *Memory) ReadDir(path string) ([]os.FileInfo, error) {
if f, has := fs.s.Get(path); has {
if target, isLink := fs.resolveLink(path, f); isLink {
return fs.ReadDir(target)
if target != path {
return fs.ReadDir(target)
}
}
} else {
return nil, &os.PathError{Op: "open", Path: path, Err: syscall.ENOENT}
Expand Down Expand Up @@ -176,17 +177,19 @@ func (fs *Memory) Remove(filename string) error {
return fs.s.Remove(filename)
}

// Falls back to Go's filepath.Join, which works differently depending on the
// OS where the code is being executed.
func (fs *Memory) Join(elem ...string) string {
return filepath.Join(elem...)
}

func (fs *Memory) Symlink(target, link string) error {
_, err := fs.Stat(link)
_, err := fs.Lstat(link)
if err == nil {
return os.ErrExist
}

if !os.IsNotExist(err) {
if !errors.Is(err, os.ErrNotExist) {
return err
}

Expand Down Expand Up @@ -237,7 +240,7 @@ func (f *file) Read(b []byte) (int, error) {
n, err := f.ReadAt(b, f.position)
f.position += int64(n)

if err == io.EOF && n != 0 {
if errors.Is(err, io.EOF) && n != 0 {
err = nil
}

Expand Down
Loading

0 comments on commit 8453aa9

Please sign in to comment.