Skip to content

Commit

Permalink
fixup lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed Oct 31, 2024
1 parent 4a32325 commit 4084253
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
8 changes: 2 additions & 6 deletions cmd/tcl/kubectl-testkube/devbox/devutils/binarypatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ const (
// so the resulting patch may be bigger than it's needed.
// It's working nicely for incremental builds though.
type BinaryPatch struct {
buf *bytes.Buffer
uintTmp []byte
lastOp BinaryPatchOpType
lastCount int
buf *bytes.Buffer
}

type BinaryPatchThreshold struct {
Expand All @@ -41,8 +38,7 @@ type BinaryPatchThreshold struct {

func NewBinaryPatch() *BinaryPatch {
return &BinaryPatch{
buf: bytes.NewBuffer(nil),
uintTmp: make([]byte, 4),
buf: bytes.NewBuffer(nil),
}
}

Expand Down
48 changes: 25 additions & 23 deletions cmd/tcl/kubectl-testkube/devbox/devutils/binarystorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,33 +238,35 @@ func (r *BinaryStorage) upload(ctx context.Context, name string, binary *Binary)

if binary.hash != "" && binary.prevHash != "" && r.Is(name, binary.prevHash) {
contents, err := binary.patch()
gzipContents := bytes.NewBuffer(nil)
gz := gzip.NewWriter(gzipContents)
io.Copy(gz, bytes.NewBuffer(contents))
gz.Flush()
gz.Close()
if err == nil {
gzipContents := bytes.NewBuffer(nil)
gz := gzip.NewWriter(gzipContents)
io.Copy(gz, bytes.NewBuffer(contents))
gz.Flush()
gz.Close()

gzipContentsLen := gzipContents.Len()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, fmt.Sprintf("http://localhost:%d/%s", r.localPort, name), gzipContents)
if err != nil {
if ctx.Err() != nil {
return 0, err
}
fmt.Printf("error while sending %s patch, fallback to full stream: %s\n", name, err)
} else {
req.ContentLength = int64(gzipContentsLen)
req.Header.Set("Content-Encoding", "gzip")
req.Header.Set("X-Prev-Hash", binary.prevHash)
req.Header.Set("X-Hash", binary.hash)
res, err := client.Do(req)
gzipContentsLen := gzipContents.Len()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, fmt.Sprintf("http://localhost:%d/%s", r.localPort, name), gzipContents)
if err != nil {
if ctx.Err() != nil {
return 0, err
}
fmt.Printf("error while sending %s patch, fallback to full stream: %s\n", name, err)
} else if res.StatusCode != http.StatusOK {
b, _ := io.ReadAll(res.Body)
fmt.Printf("error while sending %s patch, fallback to full stream: status code: %s, message: %s\n", name, res.Status, string(b))
} else {
r.SetHash(name, binary.hash)
return gzipContentsLen, nil
req.ContentLength = int64(gzipContentsLen)
req.Header.Set("Content-Encoding", "gzip")
req.Header.Set("X-Prev-Hash", binary.prevHash)
req.Header.Set("X-Hash", binary.hash)
res, err := client.Do(req)
if err != nil {
fmt.Printf("error while sending %s patch, fallback to full stream: %s\n", name, err)
} else if res.StatusCode != http.StatusOK {
b, _ := io.ReadAll(res.Body)
fmt.Printf("error while sending %s patch, fallback to full stream: status code: %s, message: %s\n", name, res.Status, string(b))
} else {
r.SetHash(name, binary.hash)
return gzipContentsLen, nil
}
}
}
}
Expand Down

0 comments on commit 4084253

Please sign in to comment.