mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
2402296e9a
* fix: migrate to Go module v2 for proper semantic versioning This change updates the module path from 'zotregistry.dev/zot' to 'zotregistry.dev/zot/v2' to comply with Go's semantic versioning rules. According to Go's module versioning requirements, major version v2+ must include the major version in the module path. The current module path 'zotregistry.dev/zot' only supports v0.x.x and v1.x.x versions, making existing v2.x.x tags (like v2.1.8) unusable. Changes: - Updated go.mod module path to zotregistry.dev/zot/v2 - Updated all internal import paths across 280+ Go source files - Updated configuration files (golangcilint.yaml, gqlgen.yml) - Updated README.md Go reference badge This fix enables proper use of existing v2.x.x Git tags and allows external packages to import zot v2+ versions without compatibility errors. Resolves: Go module import compatibility for v2+ versions Fixes: #3071 Signed-off-by: Luca Muscariello <muscariello@ieee.org> * fix: regenerate GraphQL files with updated v2 import paths The gqlgen tool needs to regenerate the GraphQL schema files after the module path change to use the new v2 imports. Signed-off-by: Luca Muscariello <muscariello@ieee.org> --------- Signed-off-by: Luca Muscariello <muscariello@ieee.org>
116 lines
2.9 KiB
Go
116 lines
2.9 KiB
Go
package s3
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
// Add s3 support.
|
|
"github.com/distribution/distribution/v3/registry/storage/driver"
|
|
_ "github.com/distribution/distribution/v3/registry/storage/driver/s3-aws"
|
|
|
|
storageConstants "zotregistry.dev/zot/v2/pkg/storage/constants"
|
|
)
|
|
|
|
type Driver struct {
|
|
store driver.StorageDriver
|
|
}
|
|
|
|
func New(storeDriver driver.StorageDriver) *Driver {
|
|
return &Driver{store: storeDriver}
|
|
}
|
|
|
|
func (driver *Driver) Name() string {
|
|
return storageConstants.S3StorageDriverName
|
|
}
|
|
|
|
func (driver *Driver) EnsureDir(path string) error {
|
|
return nil
|
|
}
|
|
|
|
func (driver *Driver) DirExists(path string) bool {
|
|
if fi, err := driver.store.Stat(context.Background(), path); err == nil && fi.IsDir() {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (driver *Driver) Reader(path string, offset int64) (io.ReadCloser, error) {
|
|
return driver.store.Reader(context.Background(), path, offset)
|
|
}
|
|
|
|
func (driver *Driver) ReadFile(path string) ([]byte, error) {
|
|
return driver.store.GetContent(context.Background(), path)
|
|
}
|
|
|
|
func (driver *Driver) Delete(path string) error {
|
|
return driver.store.Delete(context.Background(), path)
|
|
}
|
|
|
|
func (driver *Driver) Stat(path string) (driver.FileInfo, error) {
|
|
return driver.store.Stat(context.Background(), path)
|
|
}
|
|
|
|
func (driver *Driver) Writer(filepath string, append bool) (driver.FileWriter, error) { //nolint:predeclared
|
|
return driver.store.Writer(context.Background(), filepath, append)
|
|
}
|
|
|
|
func (driver *Driver) WriteFile(filepath string, content []byte) (int, error) {
|
|
var n int
|
|
|
|
if stwr, err := driver.store.Writer(context.Background(), filepath, false); err == nil {
|
|
defer stwr.Close()
|
|
|
|
if n, err = stwr.Write(content); err != nil {
|
|
return -1, err
|
|
}
|
|
|
|
if err := stwr.Commit(context.Background()); err != nil {
|
|
return -1, err
|
|
}
|
|
} else {
|
|
return -1, err
|
|
}
|
|
|
|
return n, nil
|
|
}
|
|
|
|
func (driver *Driver) Walk(path string, f driver.WalkFn) error {
|
|
return driver.store.Walk(context.Background(), path, f)
|
|
}
|
|
|
|
func (driver *Driver) List(fullpath string) ([]string, error) {
|
|
return driver.store.List(context.Background(), fullpath)
|
|
}
|
|
|
|
func (driver *Driver) Move(sourcePath string, destPath string) error {
|
|
return driver.store.Move(context.Background(), sourcePath, destPath)
|
|
}
|
|
|
|
func (driver *Driver) SameFile(path1, path2 string) bool {
|
|
fi1, _ := driver.store.Stat(context.Background(), path1)
|
|
|
|
fi2, _ := driver.store.Stat(context.Background(), path2)
|
|
|
|
if fi1 != nil && fi2 != nil {
|
|
if fi1.IsDir() == fi2.IsDir() &&
|
|
fi1.ModTime() == fi2.ModTime() &&
|
|
fi1.Path() == fi2.Path() &&
|
|
fi1.Size() == fi2.Size() {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
/*
|
|
Link put an empty file that will act like a link between the original file and deduped one
|
|
|
|
because s3 doesn't support symlinks, wherever the storage will encounter an empty file, it will get the original one
|
|
from cache.
|
|
*/
|
|
func (driver *Driver) Link(src, dest string) error {
|
|
return driver.store.PutContent(context.Background(), dest, []byte{})
|
|
}
|