-
Notifications
You must be signed in to change notification settings - Fork 220
clean chart cache dir on error processing #281
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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))
}
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
No description provided.