Browse Source

Merge pull request #7983 from vbatts/vbatts-tarsum_switch_names

tarsum: TarSum should be the interface
Tibor Vass 10 years ago
parent
commit
23f490427f
3 changed files with 22 additions and 19 deletions
  1. 6 6
      builder/evaluator.go
  2. 4 1
      builder/internals.go
  3. 12 12
      pkg/tarsum/tarsum.go

+ 6 - 6
builder/evaluator.go

@@ -93,12 +93,12 @@ type Builder struct {
 	// both of these are controlled by the Remove and ForceRemove options in BuildOpts
 	// both of these are controlled by the Remove and ForceRemove options in BuildOpts
 	TmpContainers map[string]struct{} // a map of containers used for removes
 	TmpContainers map[string]struct{} // a map of containers used for removes
 
 
-	dockerfile  *parser.Node           // the syntax tree of the dockerfile
-	image       string                 // image name for commit processing
-	maintainer  string                 // maintainer name. could probably be removed.
-	cmdSet      bool                   // indicates is CMD was set in current Dockerfile
-	context     tarsum.TarSumInterface // the context is a tarball that is uploaded by the client
-	contextPath string                 // the path of the temporary directory the local context is unpacked to (server side)
+	dockerfile  *parser.Node  // the syntax tree of the dockerfile
+	image       string        // image name for commit processing
+	maintainer  string        // maintainer name. could probably be removed.
+	cmdSet      bool          // indicates is CMD was set in current Dockerfile
+	context     tarsum.TarSum // the context is a tarball that is uploaded by the client
+	contextPath string        // the path of the temporary directory the local context is unpacked to (server side)
 
 
 }
 }
 
 

+ 4 - 1
builder/internals.go

@@ -168,7 +168,10 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowDecomp
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
-		tarSum := &tarsum.TarSum{Reader: r, DisableCompression: true}
+		tarSum, err := tarsum.NewTarSum(r, true, tarsum.Version0)
+		if err != nil {
+			return err
+		}
 		if _, err := io.Copy(ioutil.Discard, tarSum); err != nil {
 		if _, err := io.Copy(ioutil.Discard, tarSum); err != nil {
 			return err
 			return err
 		}
 		}

+ 12 - 12
pkg/tarsum/tarsum.go

@@ -28,24 +28,24 @@ const (
 // This is used for calculating checksums of layers of an image, in some cases
 // This is used for calculating checksums of layers of an image, in some cases
 // including the byte payload of the image's json metadata as well, and for
 // including the byte payload of the image's json metadata as well, and for
 // calculating the checksums for buildcache.
 // calculating the checksums for buildcache.
-func NewTarSum(r io.Reader, dc bool, v Version) (TarSumInterface, error) {
+func NewTarSum(r io.Reader, dc bool, v Version) (TarSum, error) {
 	if _, ok := tarSumVersions[v]; !ok {
 	if _, ok := tarSumVersions[v]; !ok {
 		return nil, ErrVersionNotImplemented
 		return nil, ErrVersionNotImplemented
 	}
 	}
-	return &TarSum{Reader: r, DisableCompression: dc, tarSumVersion: v}, nil
+	return &tarSum{Reader: r, DisableCompression: dc, tarSumVersion: v}, nil
 }
 }
 
 
-// TarSumInterface is the generic interface for calculating fixed time
+// TarSum is the generic interface for calculating fixed time
 // checksums of a tar archive
 // checksums of a tar archive
-type TarSumInterface interface {
+type TarSum interface {
 	io.Reader
 	io.Reader
 	GetSums() map[string]string
 	GetSums() map[string]string
 	Sum([]byte) string
 	Sum([]byte) string
 	Version() Version
 	Version() Version
 }
 }
 
 
-// TarSum struct is the structure for a Version0 checksum calculation
-type TarSum struct {
+// tarSum struct is the structure for a Version0 checksum calculation
+type tarSum struct {
 	io.Reader
 	io.Reader
 	tarR               *tar.Reader
 	tarR               *tar.Reader
 	tarW               *tar.Writer
 	tarW               *tar.Writer
@@ -62,11 +62,11 @@ type TarSum struct {
 	tarSumVersion      Version // this field is not exported so it can not be mutated during use
 	tarSumVersion      Version // this field is not exported so it can not be mutated during use
 }
 }
 
 
-func (ts TarSum) Version() Version {
+func (ts tarSum) Version() Version {
 	return ts.tarSumVersion
 	return ts.tarSumVersion
 }
 }
 
 
-func (ts TarSum) selectHeaders(h *tar.Header, v Version) (set [][2]string) {
+func (ts tarSum) selectHeaders(h *tar.Header, v Version) (set [][2]string) {
 	for _, elem := range [][2]string{
 	for _, elem := range [][2]string{
 		{"name", h.Name},
 		{"name", h.Name},
 		{"mode", strconv.Itoa(int(h.Mode))},
 		{"mode", strconv.Itoa(int(h.Mode))},
@@ -89,7 +89,7 @@ func (ts TarSum) selectHeaders(h *tar.Header, v Version) (set [][2]string) {
 	return
 	return
 }
 }
 
 
-func (ts *TarSum) encodeHeader(h *tar.Header) error {
+func (ts *tarSum) encodeHeader(h *tar.Header) error {
 	for _, elem := range ts.selectHeaders(h, ts.Version()) {
 	for _, elem := range ts.selectHeaders(h, ts.Version()) {
 		if _, err := ts.h.Write([]byte(elem[0] + elem[1])); err != nil {
 		if _, err := ts.h.Write([]byte(elem[0] + elem[1])); err != nil {
 			return err
 			return err
@@ -98,7 +98,7 @@ func (ts *TarSum) encodeHeader(h *tar.Header) error {
 	return nil
 	return nil
 }
 }
 
 
-func (ts *TarSum) Read(buf []byte) (int, error) {
+func (ts *tarSum) Read(buf []byte) (int, error) {
 	if ts.gz == nil {
 	if ts.gz == nil {
 		ts.bufTar = bytes.NewBuffer([]byte{})
 		ts.bufTar = bytes.NewBuffer([]byte{})
 		ts.bufGz = bytes.NewBuffer([]byte{})
 		ts.bufGz = bytes.NewBuffer([]byte{})
@@ -197,7 +197,7 @@ func (ts *TarSum) Read(buf []byte) (int, error) {
 	return ts.bufGz.Read(buf)
 	return ts.bufGz.Read(buf)
 }
 }
 
 
-func (ts *TarSum) Sum(extra []byte) string {
+func (ts *tarSum) Sum(extra []byte) string {
 	var sums []string
 	var sums []string
 
 
 	for _, sum := range ts.sums {
 	for _, sum := range ts.sums {
@@ -217,6 +217,6 @@ func (ts *TarSum) Sum(extra []byte) string {
 	return checksum
 	return checksum
 }
 }
 
 
-func (ts *TarSum) GetSums() map[string]string {
+func (ts *tarSum) GetSums() map[string]string {
 	return ts.sums
 	return ts.sums
 }
 }