cleanConfigDirectory removes old, unused configuration and index formats, a suitable time after they have gone out of fashion.
()
| 786 | // cleanConfigDirectory removes old, unused configuration and index formats, a |
| 787 | // suitable time after they have gone out of fashion. |
| 788 | func cleanConfigDirectory() { |
| 789 | patterns := map[string]time.Duration{ |
| 790 | "panic-*.log": 7 * 24 * time.Hour, // keep panic logs for a week |
| 791 | "audit-*.log": 7 * 24 * time.Hour, // keep audit logs for a week |
| 792 | "index-v0.14.0.db-migrated": 14 * 24 * time.Hour, // keep old index format for two weeks |
| 793 | "config.xml.v*": 30 * 24 * time.Hour, // old config versions for a month |
| 794 | "support-bundle-*": 30 * 24 * time.Hour, // keep old support bundle zip or folder for a month |
| 795 | } |
| 796 | |
| 797 | locations := slices.Compact([]string{ |
| 798 | locations.GetBaseDir(locations.ConfigBaseDir), |
| 799 | locations.GetBaseDir(locations.DataBaseDir), |
| 800 | }) |
| 801 | for _, loc := range locations { |
| 802 | fs := fs.NewFilesystem(fs.FilesystemTypeBasic, loc) |
| 803 | for pat, dur := range patterns { |
| 804 | entries, err := fs.Glob(pat) |
| 805 | if err != nil { |
| 806 | slog.Warn("Failed to clean config directory", slogutil.Error(err)) |
| 807 | continue |
| 808 | } |
| 809 | |
| 810 | for _, entry := range entries { |
| 811 | info, err := fs.Lstat(entry) |
| 812 | if err != nil { |
| 813 | slog.Warn("Failed to clean config directory", slogutil.Error(err)) |
| 814 | continue |
| 815 | } |
| 816 | |
| 817 | if time.Since(info.ModTime()) > dur { |
| 818 | if err = fs.RemoveAll(entry); err != nil { |
| 819 | slog.Warn("Failed to clean config directory", slogutil.Error(err)) |
| 820 | } else { |
| 821 | slog.Warn("Cleaned away old file", slogutil.FilePath(filepath.Base(entry))) |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | func setPauseState(cfgWrapper config.Wrapper, paused bool) { |
| 830 | _, err := cfgWrapper.Modify(func(cfg *config.Configuration) { |
no test coverage detected