MCPcopy
hub / github.com/rclone/rclone / Statfs

Method Statfs

vfs/vfs.go:659–713  ·  view source on GitHub ↗

Statfs returns into about the filing system if known The values will be -1 if they aren't known This information is cached for the DirCacheTime interval

()

Source from the content-addressed store, hash-verified

657//
658// This information is cached for the DirCacheTime interval
659func (vfs *VFS) Statfs() (total, used, free int64) {
660 // defer log.Trace("/", "")("total=%d, used=%d, free=%d", &total, &used, &free)
661 vfs.usageMu.Lock()
662 defer vfs.usageMu.Unlock()
663 total, used, free = -1, -1, -1
664 doAbout := vfs.f.Features().About
665 if (doAbout != nil || vfs.Opt.UsedIsSize) && (vfs.usageTime.IsZero() || time.Since(vfs.usageTime) >= time.Duration(vfs.Opt.DirCacheTime)) {
666 var err error
667 ctx := vfs.ctx
668 if doAbout == nil {
669 vfs.usage = &fs.Usage{}
670 } else {
671 vfs.usage, err = doAbout(ctx)
672 }
673 if vfs.Opt.UsedIsSize {
674 var usedBySizeAlgorithm int64
675 // Algorithm from `rclone size`
676 err = walk.ListR(ctx, vfs.f, "", true, -1, walk.ListObjects, func(entries fs.DirEntries) error {
677 entries.ForObject(func(o fs.Object) {
678 usedBySizeAlgorithm += o.Size()
679 })
680 return nil
681 })
682 vfs.usage.Used = &usedBySizeAlgorithm
683 // if we read a Total size then we should calculate Free from it
684 if vfs.usage.Total != nil {
685 vfs.usage.Free = nil
686 }
687 }
688 vfs.usageTime = time.Now()
689 if err != nil {
690 fs.Errorf(vfs.f, "Statfs failed: %v", err)
691 return
692 }
693 }
694
695 if u := vfs.usage; u != nil {
696 if u.Total != nil {
697 total = *u.Total
698 }
699 if u.Free != nil {
700 free = *u.Free
701 }
702 if u.Used != nil {
703 used = *u.Used
704 }
705 }
706
707 if int64(vfs.Opt.DiskSpaceTotalSize) >= 0 {
708 total = int64(vfs.Opt.DiskSpaceTotalSize)
709 }
710
711 total, used, free = fillInMissingSizes(total, used, free, unknownFreeBytes)
712 return
713}
714
715// Remove removes the named file or (empty) directory.
716func (vfs *VFS) Remove(name string) error {

Callers 5

AboutMethod · 0.45
AboutMethod · 0.45
NewFunction · 0.45
NewFunction · 0.45
TestVFSStatfsFunction · 0.45

Calls 9

ListRFunction · 0.92
ErrorfFunction · 0.92
fillInMissingSizesFunction · 0.85
IsZeroMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
FeaturesMethod · 0.65
SizeMethod · 0.65
ForObjectMethod · 0.45

Tested by 1

TestVFSStatfsFunction · 0.36