Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/download: close files after extracting in tar #310

Merged
merged 2 commits into from
Aug 22, 2019

Conversation

ahmetb
Copy link
Member

@ahmetb ahmetb commented Aug 22, 2019

  • Close file handle after extracting files on windows in extractTARGZ().
  • Also ensure we close when io.Copy fails on extractZIP().
  • Log the ignored error from the cleanup of DownloadPath.

Fixes #308.

- Close file handle after extracting files on windows in extractTARGZ().
- Also ensure we close when io.Copy fails on extractZIP().
- Log the ignored error from the cleanup of DownloadPath.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 22, 2019
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 22, 2019
Copy link
Contributor

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigating this nasty bug. I have minor questions.

@@ -131,9 +132,12 @@ func extractTARGZ(targetDir string, at io.ReaderAt, size int64) error {
if err != nil {
return errors.Wrapf(err, "failed to create file %q", path)
}
close := func() { f.Close() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a defer f.Close() not be a cleaner solution?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could end up with have thousands of files open and end up exceeding open fd limit. no need to delay.

@@ -74,15 +74,16 @@ func extractZIP(targetDir string, read io.ReaderAt, size int64) error {
if err != nil {
return errors.Wrap(err, "can't create file in zip destination dir")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should src.Close() here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think this is valid.

@@ -74,15 +74,16 @@ func extractZIP(targetDir string, read io.ReaderAt, size int64) error {
if err != nil {
return errors.Wrap(err, "can't create file in zip destination dir")
}
close := func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite see why defer can't be used here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would defer until all of the files are extracted.

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
@codecov-io
Copy link

codecov-io commented Aug 22, 2019

Codecov Report

Merging #310 into master will increase coverage by 0.05%.
The diff coverage is 54.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #310      +/-   ##
==========================================
+ Coverage   55.66%   55.72%   +0.05%     
==========================================
  Files          19       19              
  Lines         918      926       +8     
==========================================
+ Hits          511      516       +5     
- Misses        355      358       +3     
  Partials       52       52
Impacted Files Coverage Δ
pkg/installation/install.go 38.98% <0%> (ø) ⬆️
pkg/download/downloader.go 67.3% <66.66%> (-0.74%) ⬇️
pkg/index/indexscanner/scanner.go 70.21% <0%> (+0.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82e6899...ee65e0d. Read the comment docs.

@corneliusweig
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 22, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, corneliusweig

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [ahmetb,corneliusweig]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit bc7b73b into kubernetes-sigs:master Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Installing some plugins broken on windows
4 participants