dirSize sums the byte sizes of files with the given extension under dir. Returns 0 if the directory is missing or empty.
(dir, ext string)
| 201 | // dirSize sums the byte sizes of files with the given extension under dir. |
| 202 | // Returns 0 if the directory is missing or empty. |
| 203 | func dirSize(dir, ext string) int64 { |
| 204 | entries, err := os.ReadDir(dir) |
| 205 | if err != nil { |
| 206 | return 0 |
| 207 | } |
| 208 | var total int64 |
| 209 | for _, e := range entries { |
| 210 | if e.IsDir() || !strings.HasSuffix(e.Name(), ext) { |
| 211 | continue |
| 212 | } |
| 213 | fi, err := e.Info() |
| 214 | if err != nil { |
| 215 | continue |
| 216 | } |
| 217 | total += fi.Size() |
| 218 | } |
| 219 | return total |
| 220 | } |
| 221 | |
| 222 | // ParseSince converts a --since value to a lower-bound time. "all"/"" → zero |
| 223 | // (no bound); "<N>d" → now minus N days; otherwise RFC3339. |