Skip to content

Commit

Permalink
fix(manifest): Close file before renaming (#948)
Browse files Browse the repository at this point in the history
Approved-by: Alexander Jung <alex@unikraft.io>
  • Loading branch information
nderjung committed Nov 1, 2023
2 parents 7299009 + 3c1a3b6 commit f92f5b2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions manifest/pack_pull_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func pullArchive(ctx context.Context, manifest *Manifest, opts ...pack.PullOptio
return fmt.Errorf("could not create cache file: %v", err)
}

defer f.Close()

get, err := http.NewRequestWithContext(ctx, "GET", resource, nil)
if err != nil {
return err
Expand Down Expand Up @@ -157,6 +155,11 @@ func pullArchive(ctx context.Context, manifest *Manifest, opts ...pack.PullOptio
return err
}

err = f.Close()
if err != nil {
return fmt.Errorf("could not close file '%s' %s", tmpCache, err)
}

if popts.CalculateChecksum() {
log.G(ctx).Debugf("calculating checksum for manifest package...")

Expand All @@ -168,7 +171,6 @@ func pullArchive(ctx context.Context, manifest *Manifest, opts ...pack.PullOptio
if err != nil {
return fmt.Errorf("could not perform checksum: %v", err)
}
defer f.Close()

h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
Expand All @@ -179,6 +181,11 @@ func pullArchive(ctx context.Context, manifest *Manifest, opts ...pack.PullOptio
return fmt.Errorf("checksum of package does not match")
}

err = f.Close()
if err != nil {
return fmt.Errorf("could not close file '%s' %s", tmpCache, err)
}

log.G(ctx).WithFields(logrus.Fields{
"url": resource,
"checksum": checksum,
Expand Down

0 comments on commit f92f5b2

Please sign in to comment.