mirror of https://github.com/docker/docs.git
Log files name along with their checksum in TarSum + add a Method to retrieve the checksum map
This commit is contained in:
parent
1d4b7d8fa1
commit
fc9f4d8bad
|
@ -14,15 +14,16 @@ import (
|
||||||
|
|
||||||
type TarSum struct {
|
type TarSum struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
tarR *tar.Reader
|
tarR *tar.Reader
|
||||||
tarW *tar.Writer
|
tarW *tar.Writer
|
||||||
gz *gzip.Writer
|
gz *gzip.Writer
|
||||||
bufTar *bytes.Buffer
|
bufTar *bytes.Buffer
|
||||||
bufGz *bytes.Buffer
|
bufGz *bytes.Buffer
|
||||||
h hash.Hash
|
h hash.Hash
|
||||||
sums []string
|
sums map[string]string
|
||||||
finished bool
|
currentFile string
|
||||||
first bool
|
finished bool
|
||||||
|
first bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TarSum) encodeHeader(h *tar.Header) error {
|
func (ts *TarSum) encodeHeader(h *tar.Header) error {
|
||||||
|
@ -59,6 +60,7 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
|
||||||
ts.h = sha256.New()
|
ts.h = sha256.New()
|
||||||
ts.h.Reset()
|
ts.h.Reset()
|
||||||
ts.first = true
|
ts.first = true
|
||||||
|
ts.sums = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ts.finished {
|
if ts.finished {
|
||||||
|
@ -73,7 +75,7 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if !ts.first {
|
if !ts.first {
|
||||||
ts.sums = append(ts.sums, hex.EncodeToString(ts.h.Sum(nil)))
|
ts.sums[ts.currentFile] = hex.EncodeToString(ts.h.Sum(nil))
|
||||||
ts.h.Reset()
|
ts.h.Reset()
|
||||||
} else {
|
} else {
|
||||||
ts.first = false
|
ts.first = false
|
||||||
|
@ -131,12 +133,17 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TarSum) Sum(extra []byte) string {
|
func (ts *TarSum) Sum(extra []byte) string {
|
||||||
sort.Strings(ts.sums)
|
var sums []string
|
||||||
|
|
||||||
|
for _, sum := range ts.sums {
|
||||||
|
sums = append(sums, sum)
|
||||||
|
}
|
||||||
|
sort.Strings(sums)
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
if extra != nil {
|
if extra != nil {
|
||||||
h.Write(extra)
|
h.Write(extra)
|
||||||
}
|
}
|
||||||
for _, sum := range ts.sums {
|
for _, sum := range sums {
|
||||||
Debugf("-->%s<--", sum)
|
Debugf("-->%s<--", sum)
|
||||||
h.Write([]byte(sum))
|
h.Write([]byte(sum))
|
||||||
}
|
}
|
||||||
|
@ -144,3 +151,7 @@ func (ts *TarSum) Sum(extra []byte) string {
|
||||||
Debugf("checksum processed: %s", checksum)
|
Debugf("checksum processed: %s", checksum)
|
||||||
return checksum
|
return checksum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ts *TarSum) GetSums() map[string]string {
|
||||||
|
return ts.sums
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue