mirror of
https://github.com/hanzoai/s3.git
synced 2026-11-03 03:07:41 +00:00
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.
- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
"Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
(replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
keep their upstream import paths with zero churn. Internal identifiers and
import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
help/usage/flag strings, shell autocomplete program name, and the product name
in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
(e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
`cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
updated to ignore the `s3` build output.
110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
package s3_backend
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sync"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
|
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
)
|
|
|
|
func uploadToS3(sess s3iface.S3API, filename string, destBucket string, destKey string, storageClass string, fn func(progressed int64, percentage float32) error) (fileSize int64, err error) {
|
|
|
|
//open the file
|
|
f, err := os.Open(filename)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("failed to open file %q, %v", filename, err)
|
|
}
|
|
defer f.Close()
|
|
|
|
info, err := f.Stat()
|
|
if err != nil {
|
|
return 0, fmt.Errorf("failed to stat file %q, %v", filename, err)
|
|
}
|
|
|
|
fileSize = info.Size()
|
|
|
|
partSize := int64(64 * 1024 * 1024) // The minimum/default allowed part size is 5MB
|
|
for partSize*1000 < fileSize {
|
|
partSize *= 4
|
|
}
|
|
|
|
// Create an uploader with the session and custom options
|
|
uploader := s3manager.NewUploaderWithClient(sess, func(u *s3manager.Uploader) {
|
|
u.PartSize = partSize
|
|
u.Concurrency = 5
|
|
})
|
|
|
|
fileReader := &s3UploadProgressedReader{
|
|
fp: f,
|
|
size: fileSize,
|
|
signMap: map[int64]struct{}{},
|
|
fn: fn,
|
|
}
|
|
|
|
// Upload the file to S3.
|
|
var result *s3manager.UploadOutput
|
|
result, err = uploader.Upload(&s3manager.UploadInput{
|
|
Bucket: aws.String(destBucket),
|
|
Key: aws.String(destKey),
|
|
Body: fileReader,
|
|
StorageClass: aws.String(storageClass),
|
|
})
|
|
|
|
//in case it fails to upload
|
|
if err != nil {
|
|
return 0, fmt.Errorf("failed to upload file %s: %v", filename, err)
|
|
}
|
|
glog.V(1).Infof("file %s uploaded to %s\n", filename, result.Location)
|
|
|
|
return
|
|
}
|
|
|
|
// adapted from https://github.com/aws/aws-sdk-go/pull/1868
|
|
// https://github.com/aws/aws-sdk-go/blob/main/example/service/s3/putObjectWithProcess/putObjWithProcess.go
|
|
type s3UploadProgressedReader struct {
|
|
fp *os.File
|
|
size int64
|
|
read int64
|
|
signMap map[int64]struct{}
|
|
mux sync.Mutex
|
|
fn func(progressed int64, percentage float32) error
|
|
}
|
|
|
|
func (r *s3UploadProgressedReader) Read(p []byte) (int, error) {
|
|
return r.fp.Read(p)
|
|
}
|
|
|
|
func (r *s3UploadProgressedReader) ReadAt(p []byte, off int64) (int, error) {
|
|
n, err := r.fp.ReadAt(p, off)
|
|
if err != nil {
|
|
return n, err
|
|
}
|
|
|
|
r.mux.Lock()
|
|
// Ignore the first signature call
|
|
if _, ok := r.signMap[off]; ok {
|
|
r.read += int64(n)
|
|
} else {
|
|
r.signMap[off] = struct{}{}
|
|
}
|
|
r.mux.Unlock()
|
|
|
|
if r.fn != nil {
|
|
read := r.read
|
|
if err := r.fn(read, float32(read*100)/float32(r.size)); err != nil {
|
|
return n, err
|
|
}
|
|
}
|
|
|
|
return n, err
|
|
}
|
|
|
|
func (r *s3UploadProgressedReader) Seek(offset int64, whence int) (int64, error) {
|
|
return r.fp.Seek(offset, whence)
|
|
}
|