mirror of
https://github.com/gomods/athens
synced 2026-02-03 12:10:32 +00:00
minio : Use no. of objects for Exists check (#1276)
* minio checker: check len instead of mod only * fix syntax err * fix err * handle list errs
This commit is contained in:
committed by
Aaron Schlesinger
parent
3bda516c19
commit
5cec5f6366
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gomods/athens/pkg/errors"
|
"github.com/gomods/athens/pkg/errors"
|
||||||
"github.com/gomods/athens/pkg/observ"
|
"github.com/gomods/athens/pkg/observ"
|
||||||
minio "github.com/minio/minio-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -19,15 +18,28 @@ func (v *storageImpl) Exists(ctx context.Context, module, version string) (bool,
|
|||||||
defer span.End()
|
defer span.End()
|
||||||
versionedPath := v.versionLocation(module, version)
|
versionedPath := v.versionLocation(module, version)
|
||||||
modPath := fmt.Sprintf("%s/go.mod", versionedPath)
|
modPath := fmt.Sprintf("%s/go.mod", versionedPath)
|
||||||
_, err := v.minioClient.StatObject(v.bucketName, modPath, minio.StatObjectOptions{})
|
infoPath := fmt.Sprintf("%s/%s.info", versionedPath, version)
|
||||||
|
zipPath := fmt.Sprintf("%s/source.zip", versionedPath)
|
||||||
if minio.ToErrorResponse(err).Code == minioErrorCodeNoSuchKey {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var count int
|
||||||
|
objectCh, err := v.minioCore.ListObjectsV2(v.bucketName, versionedPath, "", false, "", 0, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.E(op, err, errors.M(module), errors.V(version))
|
return false, errors.E(op, err, errors.M(module), errors.V(version))
|
||||||
}
|
}
|
||||||
|
for _, object := range objectCh.Contents {
|
||||||
|
if object.Err != nil {
|
||||||
|
return false, errors.E(op, object.Err, errors.M(module), errors.V(version))
|
||||||
|
}
|
||||||
|
|
||||||
return true, nil
|
switch object.Key {
|
||||||
|
case infoPath:
|
||||||
|
count++
|
||||||
|
case modPath:
|
||||||
|
count++
|
||||||
|
case zipPath:
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count == 3, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ func (l *storageImpl) List(ctx context.Context, module string) ([]string, error)
|
|||||||
doneCh := make(chan struct{})
|
doneCh := make(chan struct{})
|
||||||
defer close(doneCh)
|
defer close(doneCh)
|
||||||
searchPrefix := module + "/"
|
searchPrefix := module + "/"
|
||||||
objectCh, _ := l.minioCore.ListObjectsV2(l.bucketName, searchPrefix, "", false, "", 0, "")
|
objectCh, err := l.minioCore.ListObjectsV2(l.bucketName, searchPrefix, "", false, "", 0, "")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.E(op, err, errors.M(module))
|
||||||
|
}
|
||||||
for _, object := range objectCh.Contents {
|
for _, object := range objectCh.Contents {
|
||||||
if object.Err != nil {
|
if object.Err != nil {
|
||||||
return nil, errors.E(op, object.Err, errors.M(module))
|
return nil, errors.E(op, object.Err, errors.M(module))
|
||||||
|
|||||||
Reference in New Issue
Block a user