[ARVADOS] created: 8d9adcff3cfc57c775f136ef32dcad6b3860a5a3

Git user git at public.curoverse.com
Tue Sep 19 10:47:51 EDT 2017


        at  8d9adcff3cfc57c775f136ef32dcad6b3860a5a3 (commit)


commit 8d9adcff3cfc57c775f136ef32dcad6b3860a5a3
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Tue Sep 19 10:47:06 2017 -0400

    12247: Simplify (Hash)Sum() usage.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/sdk/go/keepclient/hashcheck.go b/sdk/go/keepclient/hashcheck.go
index 9b13eda..726b813 100644
--- a/sdk/go/keepclient/hashcheck.go
+++ b/sdk/go/keepclient/hashcheck.go
@@ -35,7 +35,7 @@ func (this HashCheckingReader) Read(p []byte) (n int, err error) {
 		this.Hash.Write(p[:n])
 	}
 	if err == io.EOF {
-		sum := this.Hash.Sum(make([]byte, 0, this.Hash.Size()))
+		sum := this.Hash.Sum(nil)
 		if fmt.Sprintf("%x", sum) != this.Check {
 			err = BadChecksum
 		}
@@ -57,7 +57,7 @@ func (this HashCheckingReader) WriteTo(dest io.Writer) (written int64, err error
 		return written, err
 	}
 
-	sum := this.Hash.Sum(make([]byte, 0, this.Hash.Size()))
+	sum := this.Hash.Sum(nil)
 	if fmt.Sprintf("%x", sum) != this.Check {
 		return written, BadChecksum
 	}
@@ -81,7 +81,7 @@ func (this HashCheckingReader) Close() (err error) {
 		return err
 	}
 
-	sum := this.Hash.Sum(make([]byte, 0, this.Hash.Size()))
+	sum := this.Hash.Sum(nil)
 	if fmt.Sprintf("%x", sum) != this.Check {
 		err = BadChecksum
 	}

commit 0a4df3791951eaa876db8046a7caca258afa693e
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Tue Sep 19 10:37:43 2017 -0400

    12247: Propagate write errors, don't hide them with "bad checksum".
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/sdk/go/keepclient/hashcheck.go b/sdk/go/keepclient/hashcheck.go
index 4a5c09b..9b13eda 100644
--- a/sdk/go/keepclient/hashcheck.go
+++ b/sdk/go/keepclient/hashcheck.go
@@ -43,8 +43,9 @@ func (this HashCheckingReader) Read(p []byte) (n int, err error) {
 	return n, err
 }
 
-// WriteTo writes the entire contents of this.Reader to dest.  Returns
-// BadChecksum if the checksum doesn't match.
+// WriteTo writes the entire contents of this.Reader to dest. Returns
+// BadChecksum if writing is successful but the checksum doesn't
+// match.
 func (this HashCheckingReader) WriteTo(dest io.Writer) (written int64, err error) {
 	if writeto, ok := this.Reader.(io.WriterTo); ok {
 		written, err = writeto.WriteTo(io.MultiWriter(dest, this.Hash))
@@ -52,13 +53,16 @@ func (this HashCheckingReader) WriteTo(dest io.Writer) (written int64, err error
 		written, err = io.Copy(io.MultiWriter(dest, this.Hash), this.Reader)
 	}
 
-	sum := this.Hash.Sum(make([]byte, 0, this.Hash.Size()))
+	if err != nil {
+		return written, err
+	}
 
+	sum := this.Hash.Sum(make([]byte, 0, this.Hash.Size()))
 	if fmt.Sprintf("%x", sum) != this.Check {
-		err = BadChecksum
+		return written, BadChecksum
 	}
 
-	return written, err
+	return written, nil
 }
 
 // Close reads all remaining data from the underlying Reader and
diff --git a/sdk/go/keepclient/hashcheck_test.go b/sdk/go/keepclient/hashcheck_test.go
index db748ee..44345af 100644
--- a/sdk/go/keepclient/hashcheck_test.go
+++ b/sdk/go/keepclient/hashcheck_test.go
@@ -8,9 +8,10 @@ import (
 	"bytes"
 	"crypto/md5"
 	"fmt"
-	. "gopkg.in/check.v1"
 	"io"
 	"io/ioutil"
+
+	. "gopkg.in/check.v1"
 )
 
 type HashcheckSuiteSuite struct{}
@@ -86,4 +87,17 @@ func (h *HashcheckSuiteSuite) TestWriteTo(c *C) {
 		c.Check(err, Equals, BadChecksum)
 		<-done
 	}
+
+	// If WriteTo stops early due to a write error, return the
+	// write error (not "bad checksum").
+	{
+		input := bytes.NewBuffer(make([]byte, 1<<26))
+		hcr := HashCheckingReader{input, md5.New(), hash}
+		r, w := io.Pipe()
+		r.Close()
+		n, err := hcr.WriteTo(w)
+		c.Check(n, Equals, int64(0))
+		c.Check(err, NotNil)
+		c.Check(err, Not(Equals), BadChecksum)
+	}
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list