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
3.2 KiB
Go
110 lines
3.2 KiB
Go
package volume_info
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
jsonpb "google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
// MaybeLoadVolumeInfo load the file data as *volume_server_pb.VolumeInfo, the returned volumeInfo will not be nil
|
|
func MaybeLoadVolumeInfo(fileName string) (volumeInfo *volume_server_pb.VolumeInfo, hasRemoteFile bool, hasVolumeInfoFile bool, err error) {
|
|
|
|
volumeInfo = &volume_server_pb.VolumeInfo{}
|
|
|
|
glog.V(1).Infof("maybeLoadVolumeInfo checks %s", fileName)
|
|
if exists, canRead, _, _, _ := util.CheckFile(fileName); !exists || !canRead {
|
|
if !exists {
|
|
return
|
|
}
|
|
hasVolumeInfoFile = true
|
|
if !canRead {
|
|
glog.Warningf("can not read %s", fileName)
|
|
err = fmt.Errorf("can not read %s", fileName)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
hasVolumeInfoFile = true
|
|
|
|
glog.V(1).Infof("maybeLoadVolumeInfo reads %s", fileName)
|
|
fileData, readErr := os.ReadFile(fileName)
|
|
if readErr != nil {
|
|
glog.Warningf("fail to read %s : %v", fileName, readErr)
|
|
err = fmt.Errorf("fail to read %s : %v", fileName, readErr)
|
|
return
|
|
|
|
}
|
|
|
|
// Handle empty .vif files gracefully - treat as if file doesn't exist
|
|
// This can happen when ec.decode copies from a source that doesn't have a .vif file
|
|
if len(fileData) == 0 {
|
|
glog.Warningf("empty volume info file %s, treating as non-existent", fileName)
|
|
hasVolumeInfoFile = false
|
|
return
|
|
}
|
|
|
|
glog.V(1).Infof("maybeLoadVolumeInfo Unmarshal volume info %v", fileName)
|
|
if err = jsonpb.Unmarshal(fileData, volumeInfo); err != nil {
|
|
if oldVersionErr := tryOldVersionVolumeInfo(fileData, volumeInfo); oldVersionErr != nil {
|
|
glog.Warningf("unmarshal error: %v oldFormat: %v", err, oldVersionErr)
|
|
err = fmt.Errorf("unmarshal error: %w oldFormat: %v", err, oldVersionErr)
|
|
return
|
|
} else {
|
|
err = nil
|
|
}
|
|
}
|
|
|
|
if len(volumeInfo.GetFiles()) == 0 {
|
|
return
|
|
}
|
|
|
|
hasRemoteFile = true
|
|
|
|
return
|
|
}
|
|
|
|
func SaveVolumeInfo(fileName string, volumeInfo *volume_server_pb.VolumeInfo) error {
|
|
|
|
if exists, _, canWrite, _, _ := util.CheckFile(fileName); exists && !canWrite {
|
|
return fmt.Errorf("failed to check %s not writable", fileName)
|
|
}
|
|
|
|
m := jsonpb.MarshalOptions{
|
|
AllowPartial: true,
|
|
EmitUnpopulated: true,
|
|
Indent: " ",
|
|
}
|
|
|
|
text, marshalErr := m.Marshal(volumeInfo)
|
|
if marshalErr != nil {
|
|
return fmt.Errorf("failed to marshal %s: %v", fileName, marshalErr)
|
|
}
|
|
|
|
if err := util.WriteFile(fileName, text, 0644); err != nil {
|
|
return fmt.Errorf("failed to write %s: %v", fileName, err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func tryOldVersionVolumeInfo(data []byte, volumeInfo *volume_server_pb.VolumeInfo) error {
|
|
oldVersionVolumeInfo := &volume_server_pb.OldVersionVolumeInfo{}
|
|
if err := jsonpb.Unmarshal(data, oldVersionVolumeInfo); err != nil {
|
|
return fmt.Errorf("failed to unmarshal old version volume info: %w", err)
|
|
}
|
|
volumeInfo.Files = oldVersionVolumeInfo.Files
|
|
volumeInfo.Version = oldVersionVolumeInfo.Version
|
|
volumeInfo.Replication = oldVersionVolumeInfo.Replication
|
|
volumeInfo.BytesOffset = oldVersionVolumeInfo.BytesOffset
|
|
volumeInfo.DatFileSize = oldVersionVolumeInfo.DatFileSize
|
|
volumeInfo.ExpireAtSec = oldVersionVolumeInfo.DestroyTime
|
|
volumeInfo.ReadOnly = oldVersionVolumeInfo.ReadOnly
|
|
|
|
return nil
|
|
}
|