[disk][host]: move back Warnings from internal to disk and host.

fix #1377
pull/1379/head
shirou 3 years ago
parent 34cc43d282
commit 4ac7e99c6a

@ -80,7 +80,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
}
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
warnings := common.Warnings{
warnings := Warnings{
Verbose: true,
}
var ret []PartitionStat

@ -1,4 +1,4 @@
package common
package disk
import "fmt"

@ -395,7 +395,7 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
}
}
var warns common.Warnings
var warns Warnings
if len(files) == 0 { // handle distributions without hwmon, like raspbian #391, parse legacy thermal_zone files
files, err = filepath.Glob(common.HostSys("/class/thermal/thermal_zone*/"))

@ -0,0 +1,30 @@
package host
import "fmt"
type Warnings struct {
List []error
Verbose bool
}
func (w *Warnings) Add(err error) {
w.List = append(w.List, err)
}
func (w *Warnings) Reference() error {
if len(w.List) > 0 {
return w
}
return nil
}
func (w *Warnings) Error() string {
if w.Verbose {
str := ""
for i, e := range w.List {
str += fmt.Sprintf("\tError %d: %s\n", i, e.Error())
}
return str
}
return fmt.Sprintf("Number of warnings: %v", len(w.List))
}
Loading…
Cancel
Save