isSharedCachePath returns true if the chartPath is within the shared cache directory. Charts in the shared cache should not be deleted during refresh to prevent race conditions when multiple processes are using the same cached chart.
(chartPath string)
| 5360 | // Charts in the shared cache should not be deleted during refresh to prevent race conditions |
| 5361 | // when multiple processes are using the same cached chart. |
| 5362 | func (st *HelmState) isSharedCachePath(chartPath string) bool { |
| 5363 | sharedCacheDir := remote.CacheDir() |
| 5364 | absChartPath, err := filepath.Abs(chartPath) |
| 5365 | if err != nil { |
| 5366 | st.logger.Debugf("failed to get absolute path for chartPath %q: %v", chartPath, err) |
| 5367 | return false |
| 5368 | } |
| 5369 | absSharedCache, err := filepath.Abs(sharedCacheDir) |
| 5370 | if err != nil { |
| 5371 | st.logger.Debugf("failed to get absolute path for shared cache dir %q: %v", sharedCacheDir, err) |
| 5372 | return false |
| 5373 | } |
| 5374 | resolvedChartPath, err := filepath.EvalSymlinks(absChartPath) |
| 5375 | if err != nil { |
| 5376 | resolvedChartPath = absChartPath |
| 5377 | } |
| 5378 | resolvedSharedCache, err := filepath.EvalSymlinks(absSharedCache) |
| 5379 | if err != nil { |
| 5380 | resolvedSharedCache = absSharedCache |
| 5381 | } |
| 5382 | return resolvedChartPath == resolvedSharedCache || |
| 5383 | strings.HasPrefix(resolvedChartPath, resolvedSharedCache+string(filepath.Separator)) |
| 5384 | } |
| 5385 | |
| 5386 | // chartDownloadAction represents what action should be taken after acquiring locks |
| 5387 | type chartDownloadAction int |