Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

clean chart cache dir on error processing #281

Merged
merged 5 commits into from
Jun 21, 2017

Conversation

prydonius
Copy link
Member

No description provided.

@prydonius prydonius requested a review from migmartri June 21, 2017 08:55
@codecov-io
Copy link

codecov-io commented Jun 21, 2017

Codecov Report

Merging #281 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #281      +/-   ##
=========================================
+ Coverage   90.35%   90.4%   +0.04%     
=========================================
  Files          18      18              
  Lines         964     969       +5     
=========================================
+ Hits          871     876       +5     
  Misses         62      62              
  Partials       31      31
Impacted Files Coverage Δ
...api/data/cache/charthelper/chart_package_helper.go 79.28% <100%> (+0.76%) ⬆️

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 3f5bf20...61e891a. Read the comment docs.

Copy link

@jbianquetti-nami jbianquetti-nami left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -134,6 +136,19 @@ var ensureChartDataDir = func(chart *models.ChartPackage) error {
return nil
}

var cleanChartDataDir = func(chart *models.ChartPackage) error {
Copy link

Choose a reason for hiding this comment

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

why is this a variable? do you intend to replace it?

or do you do that for every function just in case?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is something that we're doing for functions that need to be overridden in tests, although I'm not actually overriding it in this case. I'm not sure if it makes sense to only use a variable where we intend to test it that way. What do you think?

@@ -134,6 +136,19 @@ var ensureChartDataDir = func(chart *models.ChartPackage) error {
return nil
}

var cleanChartDataDir = func(chart *models.ChartPackage) error {
dir := chartDataDir(chart)
if _, err := os.Stat(dir); err != nil {
Copy link

Choose a reason for hiding this comment

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

why do you want to return an error if the dir doesn't exist?

i.e. I wonder why cannot this just be:

var cleanChartDataDir = func(chart *models.ChartPackage) error {
  return os.RemoveAll(chartDataDir(chart))
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point, I was copying the same structure for ensureDataDir but I think you're right in that this could be much simpler.

@@ -29,11 +29,13 @@ var DownloadAndExtractChartTarball = func(chart *models.ChartPackage) error {

if !tarballExists(chart) {
if err := downloadTarball(chart); err != nil {
cleanChartDataDir(chart)
Copy link

Choose a reason for hiding this comment

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

Just a FYI:

var DownloadAndExtractChartTarball = func(chart *models.ChartPackage) (err error) {
 	if err := ensureChartDataDir(chart); err != nil {
 		return err
 	}

 	defer func() {
 	 	if err != nil {
 	 	 	cleanChartDataDir(chart)
 	 	}
 	}()

 	if !tarballExists(chart) {
  		if err := downloadTarball(chart); err != nil {
			return err
  		}
  	}

 	if err := extractFilesFromTarball(chart); err != nil {
  		return err
  	}
  
 	return nil
}

this ensures that if you add another place where you return an error you cannot forget to delete the char data dir when the error happens.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice, I was trying to figure out how I could do this, will change it to this - thanks!

@prydonius prydonius merged commit 5cf88bd into helm:master Jun 21, 2017
@prydonius prydonius deleted the 280-fix-no-readme-err branch June 21, 2017 11:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants