diff --git a/cli/delete_cache.go b/cli/delete_cache.go index 83adb33..d69d8fd 100644 --- a/cli/delete_cache.go +++ b/cli/delete_cache.go @@ -130,15 +130,39 @@ func DeleteCacheRun(r *cmd.Root, s *cmd.Sub) { continue } - size, err := getDirSize(p) - totalSize += size - if err != nil { slog.Warn("Couldn't get directory size", "reason", err) } - slog.Info(fmt.Sprintf("Removing cache directory '%s', of size '%s", p, humanReadableFormat(float64(size)))) + var size int64 + + /* Parallelized file walk */ + err = walk.Walk(p, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if !info.IsDir() { + size += info.Size() + } + + /* Remove if file */ + if info.Mode().IsRegular() { + if err := os.Remove(path); err != nil { + slog.Warn("Could not remove file", "reason", err) + } + } + + return err + }) + + slog.Info(fmt.Sprintf("Removed cache directory '%s', of size '%s", p, humanReadableFormat(float64(size)))) + + totalSize += size + /* Remove the remaining directories */ + /* TODO: Remove() instead of RemoveAll() would be slightly faster here but the + * dirs would need to be sorted depth-first from the file walk */ if err := os.RemoveAll(p); err != nil { log.Panic("Could not remove cache directory", "reason", err) }