Skip to content

Commit 769daaf

Browse files
authored
Merge pull request #1347 from atoulme/windows_errors
Return all Windows partitions
2 parents 16b3aac + dbc0f20 commit 769daaf

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

disk/disk_windows.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
8080
}
8181

8282
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
83+
warnings := common.Warnings{
84+
Verbose: true,
85+
}
8386
var ret []PartitionStat
8487
lpBuffer := make([]byte, 254)
8588
diskret, _, err := procGetLogicalDriveStringsW.Call(
@@ -94,7 +97,9 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
9497
typepath, _ := windows.UTF16PtrFromString(path)
9598
typeret, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(typepath)))
9699
if typeret == 0 {
97-
return ret, windows.GetLastError()
100+
err := windows.GetLastError()
101+
warnings.Add(err)
102+
continue
98103
}
99104
// 2: DRIVE_REMOVABLE 3: DRIVE_FIXED 4: DRIVE_REMOTE 5: DRIVE_CDROM
100105

@@ -118,7 +123,8 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
118123
if typeret == 5 || typeret == 2 {
119124
continue // device is not ready will happen if there is no disk in the drive
120125
}
121-
return ret, err
126+
warnings.Add(err)
127+
continue
122128
}
123129
opts := []string{"rw"}
124130
if lpFileSystemFlags&fileReadOnlyVolume != 0 {
@@ -138,7 +144,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
138144
}
139145
}
140146
}
141-
return ret, nil
147+
return ret, warnings.Reference()
142148
}
143149

144150
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {

host/host_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
395395
}
396396
}
397397

398-
var warns Warnings
398+
var warns common.Warnings
399399

400400
if len(files) == 0 { // handle distributions without hwmon, like raspbian #391, parse legacy thermal_zone files
401401
files, err = filepath.Glob(common.HostSys("/class/thermal/thermal_zone*/"))

host/types.go renamed to internal/common/warnings.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package host
1+
package common
22

3-
import (
4-
"fmt"
5-
)
3+
import "fmt"
64

75
type Warnings struct {
8-
List []error
6+
List []error
7+
Verbose bool
98
}
109

1110
func (w *Warnings) Add(err error) {
@@ -20,5 +19,12 @@ func (w *Warnings) Reference() error {
2019
}
2120

2221
func (w *Warnings) Error() string {
22+
if w.Verbose {
23+
str := ""
24+
for i, e := range w.List {
25+
str += fmt.Sprintf("\tError %d: %s\n", i, e.Error())
26+
}
27+
return str
28+
}
2329
return fmt.Sprintf("Number of warnings: %v", len(w.List))
2430
}

0 commit comments

Comments
 (0)