mirror of
https://github.com/gomods/athens
synced 2026-02-03 13:20:30 +00:00
mongo: remove drop dups option and return error if module exists (#913)
This commit is contained in:
committed by
Manu Gupta
parent
132a75579b
commit
3b6aeb986e
@@ -62,7 +62,6 @@ func (m *ModuleStore) initDatabase() error {
|
||||
index := mgo.Index{
|
||||
Key: []string{"base_url", "module", "version"},
|
||||
Unique: true,
|
||||
DropDups: true,
|
||||
Background: true,
|
||||
Sparse: true,
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@ func (s *ModuleStore) Save(ctx context.Context, module, version string, mod []by
|
||||
ctx, span := observ.StartSpan(ctx, op.String())
|
||||
defer span.End()
|
||||
|
||||
exists, err := s.Exists(ctx, module, version)
|
||||
if err != nil {
|
||||
return errors.E(op, err, errors.M(module), errors.V(version))
|
||||
}
|
||||
if exists {
|
||||
return errors.E(op, "already exists", errors.M(module), errors.V(version), errors.KindAlreadyExists)
|
||||
}
|
||||
|
||||
zipName := s.gridFileName(module, version)
|
||||
fs := s.s.DB(s.d).GridFS("fs")
|
||||
f, err := fs.Create(zipName)
|
||||
|
||||
Reference in New Issue
Block a user