diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dea0063 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,22 @@ +name: Create Release +on: + push: + branches: + - main +permissions: + contents: read + +jobs: + semantic-release: + permissions: + contents: write # for codfish/semantic-release-action to create release tags + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3 + - uses: codfish/semantic-release-action@b0e57c976bf8f74b2454f59a30e4a1b5f11727b4 # v3.3.0 + id: semantic + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + outputs: + release-version: ${{ steps.semantic.outputs.release-version }} + new-release-published: ${{ steps.semantic.outputs.new-release-published }} diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..347c034 --- /dev/null +++ b/.releaserc @@ -0,0 +1,20 @@ +branches: + - name: main +plugins: + - - "@semantic-release/commit-analyzer" + - releaseRules: + - { type: doc, scope: README, release: patch } + - { type: fix, release: patch } + - { type: chore, release: patch } + - { type: refactor, release: patch } + - { type: feat, release: patch } + - { type: ci, release: patch } + - { type: style, release: patch } + parserOpts: + noteKeywords: + - MAJOR RELEASE + - "@semantic-release/release-notes-generator" + - - "@semantic-release/github" + # From: https://github.com/semantic-release/github/pull/487#issuecomment-1486298997 + - successComment: false + failTitle: false diff --git a/README.md b/README.md index 028195a..3d5842b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# s3fs [![Go Reference](https://pkg.go.dev/badge/github.com/jszwec/s3fs.svg)](https://pkg.go.dev/github.com/jszwec/s3fs) ![Go](https://github.com/jszwec/s3fs/workflows/Go/badge.svg?branch=main) +# s3fs [![Go Reference](https://pkg.go.dev/badge/github.com/flanksource/s3fs.svg)](https://pkg.go.dev/github.com/flanksource/s3fs) ![Go](https://github.com/flanksource/s3fs/workflows/Go/badge.svg?branch=main) Package s3fs provides a S3 implementation for Go1.16 [filesystem](https://tip.golang.org/pkg/io/fs/#FS) interface. @@ -6,9 +6,9 @@ Since S3 is a flat structure, s3fs simulates directories by using prefixes and "/" delim. ModTime on directories is always zero value. # SDK Versions -```github.com/jszwec/s3fs``` uses aws sdk v1 +```github.com/flanksource/s3fs``` uses aws sdk v1 -```github.com/jszwec/s3fs/v2``` uses aws sdk v2 +```github.com/flanksource/s3fs/v2``` uses aws sdk v2 # Example (SDK v1) @@ -40,7 +40,7 @@ _ = fs.WalkDir(s3fs, ".", func(path string, d fs.DirEntry, err error) error { # Installation ``` -go get github.com/jszwec/s3fs +go get github.com/flanksource/s3fs ``` # Requirements diff --git a/fs.go b/fs.go index 46feb6e..589a3d8 100644 --- a/fs.go +++ b/fs.go @@ -5,6 +5,7 @@ import ( "context" "errors" "io/fs" + "path/filepath" "github.com/aws/aws-sdk-go-v2/aws/transport/http" "github.com/aws/aws-sdk-go-v2/service/s3" @@ -45,6 +46,7 @@ type Client interface { // by using prefixes and delims ("/"). Because directories are simulated, ModTime // is always a default Time value (IsZero returns true). type S3FS struct { + prefix string cl Client bucket string readSeeker bool @@ -64,8 +66,17 @@ func New(cl Client, bucket string, opts ...Option) *S3FS { return fsys } +func (f *S3FS) WithPrefix(prefix string) *S3FS { + f.prefix = prefix + return f +} + // Open implements fs.FS. func (f *S3FS) Open(name string) (fs.File, error) { + if f.prefix != "" { + name = filepath.Join(f.prefix, name) + } + if !fs.ValidPath(name) { return nil, &fs.PathError{ Op: "open", @@ -112,6 +123,10 @@ func (f *S3FS) Open(name string) (fs.File, error) { // Stat implements fs.StatFS. func (f *S3FS) Stat(name string) (fs.FileInfo, error) { + if f.prefix != "" { + name = filepath.Join(f.prefix, name) + } + fi, err := stat(f.cl, f.bucket, name) if err != nil { return nil, &fs.PathError{ @@ -125,6 +140,10 @@ func (f *S3FS) Stat(name string) (fs.FileInfo, error) { // ReadDir implements fs.ReadDirFS. func (f *S3FS) ReadDir(name string) ([]fs.DirEntry, error) { + if f.prefix != "" { + name = filepath.Join(f.prefix, name) + } + d, err := openDir(f.cl, f.bucket, name) if err != nil { return nil, &fs.PathError{ diff --git a/fs_test.go b/fs_test.go index 1b60ca8..b776709 100644 --- a/fs_test.go +++ b/fs_test.go @@ -21,12 +21,12 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/s3/manager" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" - "github.com/jszwec/s3fs/v2" + "github.com/flanksource/s3fs/v2" ) var ( endpoint = flag.String("endpoint", "http://localhost:4566", "s3 endpoint") - bucket = flag.String("bucket", "test-github.com-jszwec-s3fs", "bucket name") + bucket = flag.String("bucket", "test-github.com-flanksource-s3fs", "bucket name") skipVerify = flag.Bool("skip-verify", true, "http insecure skip verify") ) diff --git a/go.mod b/go.mod index 9cee9dc..f020365 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/jszwec/s3fs/v2 +module github.com/flanksource/s3fs/v2 -go 1.21 +go 1.22.5 require ( github.com/aws/aws-sdk-go-v2 v1.24.0