Skip to content

Commit

Permalink
minio : Use no. of objects for Exists check (#1276)
Browse files Browse the repository at this point in the history
* minio checker: check len instead of mod only

* fix syntax err

* fix err

* handle list errs
  • Loading branch information
marpio authored and arschles committed Jun 7, 2019
1 parent 3bda516 commit 5cec5f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
26 changes: 19 additions & 7 deletions pkg/storage/minio/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/gomods/athens/pkg/errors"
"github.com/gomods/athens/pkg/observ"
minio "github.com/minio/minio-go"
)

const (
Expand All @@ -19,15 +18,28 @@ func (v *storageImpl) Exists(ctx context.Context, module, version string) (bool,
defer span.End()
versionedPath := v.versionLocation(module, version)
modPath := fmt.Sprintf("%s/go.mod", versionedPath)
_, err := v.minioClient.StatObject(v.bucketName, modPath, minio.StatObjectOptions{})

if minio.ToErrorResponse(err).Code == minioErrorCodeNoSuchKey {
return false, nil
}
infoPath := fmt.Sprintf("%s/%s.info", versionedPath, version)
zipPath := fmt.Sprintf("%s/source.zip", versionedPath)

var count int
objectCh, err := v.minioCore.ListObjectsV2(v.bucketName, versionedPath, "", false, "", 0, "")
if err != nil {
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))
}

switch object.Key {
case infoPath:
count++
case modPath:
count++
case zipPath:
count++
}
}

return true, nil
return count == 3, nil
}
5 changes: 4 additions & 1 deletion pkg/storage/minio/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ func (l *storageImpl) List(ctx context.Context, module string) ([]string, error)
doneCh := make(chan struct{})
defer close(doneCh)
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 {
if object.Err != nil {
return nil, errors.E(op, object.Err, errors.M(module))
Expand Down

0 comments on commit 5cec5f6

Please sign in to comment.