github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/publicapi/util.go (about) 1 package publicapi 2 3 import ( 4 "os/exec" 5 "strconv" 6 7 "github.com/filecoin-project/bacalhau/pkg/types" 8 "github.com/ricochet2200/go-disk-usage/du" 9 "github.com/rs/zerolog/log" 10 ) 11 12 // Function to get disk usage of path/disk 13 func MountUsage(path string) (disk types.MountStatus) { 14 usage := du.NewDiskUsage(path) 15 if usage == nil { 16 return 17 } 18 disk.All = usage.Size() 19 disk.Free = usage.Free() 20 disk.Used = usage.Used() 21 return 22 } 23 24 // use "-1" as count for just last line 25 func TailFile(count int, path string) ([]byte, error) { 26 c := exec.Command("tail", strconv.Itoa(count), path) //nolint:gosec // subprocess not at risk 27 output, err := c.Output() 28 if err != nil { 29 log.Warn().Msgf("Could not find file at %s", path) 30 return nil, err 31 } 32 return output, nil 33 }