Checking the number of bytes written to Mongo GridFS (#889)

* Checking the number of bytes written to Mongo GridFS

* adding missing import

* formatting imports
This commit is contained in:
Aaron Schlesinger
2018-11-12 11:09:16 -08:00
committed by Marwan Sulaiman
parent b59bf896fc
commit c6644f82f9
+6 -1
View File
@@ -2,6 +2,7 @@ package mongo
import (
"context"
"fmt"
"io"
"github.com/gomods/athens/pkg/errors"
@@ -23,10 +24,14 @@ func (s *ModuleStore) Save(ctx context.Context, module, version string, mod []by
}
defer f.Close()
_, err = io.Copy(f, zip) // check number of bytes written?
numBytesWritten, err := io.Copy(f, zip)
if err != nil {
return errors.E(op, err, errors.M(module), errors.V(version))
}
if numBytesWritten <= 0 {
e := fmt.Errorf("copied %d bytes to Mongo GridFS", numBytesWritten)
return errors.E(op, e, errors.M(module), errors.V(version))
}
m := &storage.Module{
Module: module,