(opts CacheOptions, gopts global.Options, args []string, term ui.Terminal)
| 57 | } |
| 58 | |
| 59 | func runCache(opts CacheOptions, gopts global.Options, args []string, term ui.Terminal) error { |
| 60 | printer := ui.NewProgressPrinter(false, gopts.Verbosity, term) |
| 61 | |
| 62 | if len(args) > 0 { |
| 63 | return errors.Fatal("the cache command expects no arguments, only options - please see `restic help cache` for usage and flags") |
| 64 | } |
| 65 | |
| 66 | if gopts.NoCache { |
| 67 | return errors.Fatal("Refusing to do anything, the cache is disabled") |
| 68 | } |
| 69 | |
| 70 | var ( |
| 71 | cachedir = gopts.CacheDir |
| 72 | err error |
| 73 | ) |
| 74 | |
| 75 | if cachedir == "" { |
| 76 | cachedir, err = cache.DefaultDir() |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if opts.Cleanup || gopts.CleanupCache { |
| 83 | oldDirs, err := cache.OlderThan(cachedir, time.Duration(opts.MaxAge)*24*time.Hour) |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | if len(oldDirs) == 0 { |
| 89 | printer.P("no old cache dirs found") |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | printer.P("remove %d old cache directories", len(oldDirs)) |
| 94 | |
| 95 | for _, item := range oldDirs { |
| 96 | dir := filepath.Join(cachedir, item.Name()) |
| 97 | err = os.RemoveAll(dir) |
| 98 | if err != nil { |
| 99 | printer.E("unable to remove %v: %v", dir, err) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return nil |
| 104 | } |
| 105 | |
| 106 | tab := table.New() |
| 107 | |
| 108 | type data struct { |
| 109 | ID string |
| 110 | Last string |
| 111 | Old string |
| 112 | Size string |
| 113 | } |
| 114 | |
| 115 | tab.AddColumn("Repo ID", "{{ .ID }}") |
| 116 | tab.AddColumn("Last Used", "{{ .Last }}") |
no test coverage detected