Download this file
| 1 | package assetcache |
| 2 | |
| 3 | import "errors" |
| 4 | |
| 5 | // FS is the store's view of the filesystem's free space. The Linux |
| 6 | // implementation is statfs; tests may supply a fake. |
| 7 | type FS interface { |
| 8 | // Space reports the size of the filesystem holding dir and the bytes |
| 9 | // available to an unprivileged writer. The store may call it with its |
| 10 | // own lock held, so it must not call back into the Store. |
| 11 | Space(dir string) (total, free uint64, err error) |
| 12 | } |
| 13 | |
| 14 | // ErrUnsupported is returned by Statfs on systems where free space is not |
| 15 | // measured. |
| 16 | var ErrUnsupported = errors.New("assetcache: free space unknown on this system") |
| 17 | |
| 18 | const ( |
| 19 | gib = 1 << 30 |
| 20 | |
| 21 | // maxDefaultBudget is the largest budget DefaultBudget returns. |
| 22 | maxDefaultBudget = 4 * gib |
| 23 | ) |
| 24 | |
| 25 | // DefaultBudget is the cache budget used when none is configured: the smaller |
| 26 | // of 4 GiB and a tenth of the filesystem's size. |
| 27 | func DefaultBudget(total uint64) int64 { |
| 28 | if total/10 >= maxDefaultBudget { |
| 29 | return maxDefaultBudget |
| 30 | } |
| 31 | return int64(total / 10) |
| 32 | } |
| 33 | |