Browse code

pkg/tarsum: actually init the TarSum struct

closes #9241

Signed-off-by: Vincent Batts <vbatts@redhat.com>

Vincent Batts authored on 2014/11/20 05:46:03
Showing 1 changed files
... ...
@@ -27,11 +27,7 @@ const (
27 27
 // including the byte payload of the image's json metadata as well, and for
28 28
 // calculating the checksums for buildcache.
29 29
 func NewTarSum(r io.Reader, dc bool, v Version) (TarSum, error) {
30
-	headerSelector, err := getTarHeaderSelector(v)
31
-	if err != nil {
32
-		return nil, err
33
-	}
34
-	return &tarSum{Reader: r, DisableCompression: dc, tarSumVersion: v, headerSelector: headerSelector}, nil
30
+	return NewTarSumHash(r, dc, v, DefaultTHash)
35 31
 }
36 32
 
37 33
 // Create a new TarSum, providing a THash to use rather than the DefaultTHash
... ...
@@ -40,7 +36,9 @@ func NewTarSumHash(r io.Reader, dc bool, v Version, tHash THash) (TarSum, error)
40 40
 	if err != nil {
41 41
 		return nil, err
42 42
 	}
43
-	return &tarSum{Reader: r, DisableCompression: dc, tarSumVersion: v, headerSelector: headerSelector, tHash: tHash}, nil
43
+	ts := &tarSum{Reader: r, DisableCompression: dc, tarSumVersion: v, headerSelector: headerSelector, tHash: tHash}
44
+	err = ts.initTarSum()
45
+	return ts, err
44 46
 }
45 47
 
46 48
 // TarSum is the generic interface for calculating fixed time
... ...
@@ -134,12 +132,6 @@ func (ts *tarSum) initTarSum() error {
134 134
 }
135 135
 
136 136
 func (ts *tarSum) Read(buf []byte) (int, error) {
137
-	if ts.writer == nil {
138
-		if err := ts.initTarSum(); err != nil {
139
-			return 0, err
140
-		}
141
-	}
142
-
143 137
 	if ts.finished {
144 138
 		return ts.bufWriter.Read(buf)
145 139
 	}