package assetcache import "errors" // FS is the store's view of the filesystem's free space. The Linux // implementation is statfs; tests may supply a fake. type FS interface { // Space reports the size of the filesystem holding dir and the bytes // available to an unprivileged writer. The store may call it with its // own lock held, so it must not call back into the Store. Space(dir string) (total, free uint64, err error) } // ErrUnsupported is returned by Statfs on systems where free space is not // measured. var ErrUnsupported = errors.New("assetcache: free space unknown on this system") const ( gib = 1 << 30 // maxDefaultBudget is the largest budget DefaultBudget returns. maxDefaultBudget = 4 * gib ) // DefaultBudget is the cache budget used when none is configured: the smaller // of 4 GiB and a tenth of the filesystem's size. func DefaultBudget(total uint64) int64 { if total/10 >= maxDefaultBudget { return maxDefaultBudget } return int64(total / 10) }