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

Bumping dependencies and forward ports #97

Merged
merged 11 commits into from
Dec 28, 2024
6 changes: 5 additions & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
interval: "monthly"
commit-message:
prefix: "build"

Expand All @@ -13,3 +13,7 @@ updates:
interval: "daily"
commit-message:
prefix: "build"
groups:
golang.org:
patterns:
- "golang.org/*"
11 changes: 6 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: "CodeQL"
name: CodeQL

on:
push:
branches: [ "master" ]
branches: [ "master", "main" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '00 5 * * 1'

permissions: {}

jobs:
analyze:
name: Analyze
Expand All @@ -28,7 +29,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
languages: ${{ matrix.language }}
# xref: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
Expand All @@ -39,6 +40,6 @@ jobs:
run: go build ./...

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3
uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 # v3.27.5
with:
category: "/language:${{matrix.language}}"
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
on: [push, pull_request]
name: Test

on:
push:
branches: [ "master", "main" ]
pull_request:

permissions: {}

jobs:
test:
strategy:
matrix:
go-version: [1.20.x,1.21.x,1.22.x]
go-version: [1.21.x,1.22.x,1.23.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/test_js.yml

This file was deleted.

10 changes: 8 additions & 2 deletions .github/workflows/test_wasip1.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
on: [push, pull_request]
name: Test wasip1

on:
push:
branches: [ "master", "main" ]
pull_request:

permissions: {}

jobs:
test:
strategy:
matrix:
go-version: [1.21.x,1.22.x]
go-version: [1.22.x,1.23.x]
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/go-git/go-billy/v5

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

require (
github.com/cyphar/filepath-securejoin v0.2.4
github.com/stretchr/testify v1.9.0
golang.org/x/sys v0.19.0
github.com/cyphar/filepath-securejoin v0.3.6
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.28.0
)

require (
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/cyphar/filepath-securejoin v0.3.6 h1:4d9N5ykBnSp5Xn2JkhocYDkOpURL/18CYMpo6xB9uWM=
github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
140 changes: 140 additions & 0 deletions helper/iofs/iofs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// Package iofs provides an adapter from billy.Filesystem to a the
// standard library io.fs.FS interface.
package iofs

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

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

// Wrap adapts a billy.Filesystem to a io.fs.FS.
func New(fs billyfs.Basic) fs.FS {
return &adapterFs{fs: polyfill.New(fs)}
}

type adapterFs struct {
fs billyfs.Filesystem
}

// 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)

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

// Open opens the named file on the underlying FS, implementing fs.FS (returning a file or error).
func (a *adapterFs) Open(name string) (fs.File, error) {
if name[0] == '/' || name != filepath.Clean(name) {
// fstest.TestFS explicitly checks that these should return error.
// MemFS performs the clean internally, so we need to block that here for testing purposes.
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid}
}
stat, err := a.fs.Stat(name)
if err != nil {
return nil, err
}
if stat.IsDir() {
entries, err := a.ReadDir(name)
if err != nil {
return nil, err
}
return makeDir(stat, entries), nil
}
file, err := a.fs.Open(name)
return &adapterFile{file: file, info: stat}, err
}

// ReadDir reads the named directory, implementing fs.ReadDirFS (returning a listing or error).
func (a *adapterFs) ReadDir(name string) ([]fs.DirEntry, error) {
items, err := a.fs.ReadDir(name)
if err != nil {
return nil, err
}
entries := make([]fs.DirEntry, len(items))
for i, item := range items {
entries[i] = fs.FileInfoToDirEntry(item)
}
return entries, nil
}

// Stat returns information on the named file, implementing fs.StatFS (returning FileInfo or error).
func (a *adapterFs) Stat(name string) (fs.FileInfo, error) {
return a.fs.Stat(name)
}

// ReadFile reads the named file and returns its contents, implementing fs.ReadFileFS (returning contents or error).
func (a *adapterFs) ReadFile(name string) ([]byte, error) {
stat, err := a.fs.Stat(name)
if err != nil {
return nil, err
}
b := make([]byte, stat.Size())
file, err := a.Open(name)
if err != nil {
return nil, err
}
defer file.Close()
_, err = file.Read(b)
return b, err
}

type adapterFile struct {
file billyfs.File
info fs.FileInfo
}

var _ fs.File = (*adapterFile)(nil)

// Close closes the file, implementing fs.File (and io.Closer).
func (a *adapterFile) Close() error {
return a.file.Close()
}

// Read reads bytes from the file, implementing fs.File (and io.Reader).
func (a *adapterFile) Read(b []byte) (int, error) {
return a.file.Read(b)
}

// Stat returns file information, implementing fs.File (returning FileInfo or error).
func (a *adapterFile) Stat() (fs.FileInfo, error) {
return a.info, nil
}

type adapterDirFile struct {
adapterFile
entries []fs.DirEntry
}

var _ fs.ReadDirFile = (*adapterDirFile)(nil)

func makeDir(stat fs.FileInfo, entries []fs.DirEntry) *adapterDirFile {
return &adapterDirFile{
adapterFile: adapterFile{info: stat},
entries: entries,
}
}

// Close closes the directory, implementing fs.File (and io.Closer).
// Subtle: note that this is shadowing adapterFile.Close.
func (a *adapterDirFile) Close() error {
return nil
}

// ReadDir reads the directory contents, implementing fs.ReadDirFile (returning directory listing or error).
func (a *adapterDirFile) ReadDir(n int) ([]fs.DirEntry, error) {
if len(a.entries) == 0 && n > 0 {
return nil, io.EOF
}
if n <= 0 || n > len(a.entries) {
n = len(a.entries)
}
entries := a.entries[:n]
a.entries = a.entries[n:]
return entries, nil
}
Loading
Loading