Skip to content

Commit

Permalink
feat: support base
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 25, 2024
1 parent 7b413ce commit 83a6635
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
20 changes: 20 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 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.

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)
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 83a6635

Please sign in to comment.