MCPcopy
hub / github.com/restic/restic / runCache

Function runCache

cmd/restic/cmd_cache.go:59–169  ·  view source on GitHub ↗
(opts CacheOptions, gopts global.Options, args []string, term ui.Terminal)

Source from the content-addressed store, hash-verified

57}
58
59func 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 }}")

Callers 1

newCacheCommandFunction · 0.85

Calls 15

NewProgressPrinterFunction · 0.92
FatalFunction · 0.92
DefaultDirFunction · 0.92
OlderThanFunction · 0.92
NewFunction · 0.92
AllFunction · 0.92
IsOldFunction · 0.92
FormatBytesFunction · 0.92
dirSizeFunction · 0.85
AddColumnMethod · 0.80
AddRowMethod · 0.80
PMethod · 0.65

Tested by

no test coverage detected