mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-21 10:23:06 +02:00
Fix chartify temp directory cleanup - track output directories for proper cleanup
Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
co-authored by
yxxhero
parent
53ee477e20
commit
e06c185667
@@ -2270,37 +2270,3 @@ func GetArgs(args string, state *state.HelmState) []string {
|
||||
|
||||
return state.HelmDefaults.Args
|
||||
}
|
||||
|
||||
// CleanupTempFiles removes leftover temporary files and directories from previous runs
|
||||
func CleanupTempFiles(logger *zap.SugaredLogger) error {
|
||||
if logger == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
tmpDir := os.TempDir()
|
||||
entries, err := os.ReadDir(tmpDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading temp directory %s: %v", tmpDir, err)
|
||||
}
|
||||
|
||||
var cleanupCount int
|
||||
for _, entry := range entries {
|
||||
name := entry.Name()
|
||||
// Clean up old helmfile and chartify temporary files/directories
|
||||
if strings.HasPrefix(name, "helmfile") || strings.HasPrefix(name, "chartify") {
|
||||
fullPath := filepath.Join(tmpDir, name)
|
||||
if err := os.RemoveAll(fullPath); err != nil {
|
||||
logger.Warnf("Failed to remove temporary file/directory %s: %v", fullPath, err)
|
||||
} else {
|
||||
logger.Debugf("Cleaned up temporary file/directory: %s", fullPath)
|
||||
cleanupCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cleanupCount > 0 {
|
||||
logger.Debugf("Cleaned up %d temporary files/directories", cleanupCount)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user