Skip to content

Commit 946855e

Browse files
committed
fix: don't close zip too early
1 parent d96666e commit 946855e

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

server/docker.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,29 +91,19 @@ func (s *Server) prepareIndexManifestForDestination(
9191
func (s *Server) prepareImageForUpload(
9292
ctx context.Context,
9393
j job.UploadableContainer,
94-
zname string,
94+
stream *zip.ReadCloser,
9595
dst *config.Destination,
9696
) (
9797
crname.Reference, cr.Image, cr.ImageIndex, error,
9898
) {
9999
l := logutils.LoggerFromContext(ctx)
100100

101-
var z *zip.ReadCloser
102-
{ // open archive
103-
_z, err := zip.OpenReader(zname)
104-
if err != nil {
105-
return nil, nil, nil, fmt.Errorf("failed to open zip file: %w", err)
106-
}
107-
defer _z.Close()
108-
z = _z
109-
}
110-
111101
errs := make([]error, 0)
112102

113103
var containers = make(map[string]*container, 0)
114104
var indexManifest *cr.IndexManifest
115105
{ // get index and images
116-
for _, f := range z.File {
106+
for _, f := range stream.File {
117107
if f.FileInfo().IsDir() {
118108
continue
119109
}
@@ -203,7 +193,7 @@ func (s *Server) prepareImageForUpload(
203193
}
204194
}
205195
if len(containers) == 0 {
206-
l.Debug("No matching platforms, skipping...")
196+
l.Info("No matching platforms, skipping...")
207197
return nil, nil, nil, utils.FlattenErrors(errs)
208198
}
209199

server/upload_gcp_docker.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"archive/zip"
55
"context"
66
"errors"
7+
"fmt"
78
"io"
89
"time"
910

@@ -28,9 +29,21 @@ func (s *Server) uploadFromZipToGcpArtifactRegistryDocker(
2829
) error {
2930
l := logutils.LoggerFromContext(ctx)
3031

31-
ref, image, index, err := s.prepareImageForUpload(ctx, j, zname, dst)
32+
var z *zip.ReadCloser
33+
{ // open archive
34+
_z, err := zip.OpenReader(zname)
35+
if err != nil {
36+
return fmt.Errorf("failed to open zip file: %w", err)
37+
}
38+
defer _z.Close()
39+
z = _z
40+
}
41+
42+
ref, image, index, err := s.prepareImageForUpload(ctx, j, z, dst)
3243
if ref == nil || (image == nil && index == nil) {
33-
l.Error("Failed to prepare image for upload", zap.Error(err))
44+
if err != nil {
45+
l.Error("Failed to prepare image for upload", zap.Error(err))
46+
}
3447
return err
3548
} else if err != nil {
3649
l.Warn("There were issues while preparing image for upload", zap.Error(err))

0 commit comments

Comments
 (0)