fork/gdu
git clone https://git.julia.blue/fork/gdu
5312bf1
master
1package device 2 3import "strings" 4 5// Device struct 6type Device struct { 7Name string 8MountPoint string 9Fstype string 10Size int64 11Free int64 12} 13 14// GetUsage returns used size of device 15func (d Device )GetUsage ()int64 { 16return d .Size - d .Free 17} 18 19// DevicesInfoGetter is type for GetDevicesInfo function 20type DevicesInfoGetter interface { 21GetMounts () (Devices ,error ) 22GetDevicesInfo () (Devices ,error ) 23} 24 25// Devices if slice of Device items 26type Devices []* Device 27 28// ByUsedSize sorts devices by used size 29type ByUsedSize Devices 30 31func (f ByUsedSize )Len ()int {return len (f ) } 32func (f ByUsedSize )Swap (i ,j int ) {f [i ],f [j ]= f [j ],f [i ] } 33func (f ByUsedSize )Less (i ,j int )bool { 34return f [i ].GetUsage ()< f [j ].GetUsage () 35} 36 37// ByName sorts devices by device name 38type ByName Devices 39 40func (f ByName )Len ()int {return len (f ) } 41func (f ByName )Swap (i ,j int ) {f [i ],f [j ]= f [j ],f [i ] } 42func (f ByName )Less (i ,j int )bool { 43return f [i ].Name < f [j ].Name 44} 45 46// GetNestedMountpointsPaths returns paths of nested mount points 47func GetNestedMountpointsPaths (path string ,mounts Devices ) []string { 48paths := make ([]string ,0 ,len (mounts )) 49 50for _ ,mount := range mounts { 51if strings .HasPrefix (mount .MountPoint ,path )&& mount .MountPoint != path { 52paths = append (paths ,mount .MountPoint ) 53 } 54 } 55return paths 56}