Skip to content

Commit b44cda7

Browse files
use select ctx for context cancellation
1 parent 9e8b2ae commit b44cda7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

disk/disk_windows.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ func processVolumesMountedAsFolders(ctx context.Context, partitionStats []Partit
142142

143143
func processVolumeLoop(ctx context.Context, nextVolHandle uintptr, volNameBuf []uint16, processedPaths map[string]struct{}, partitionStats []PartitionStat, warnings Warnings) []PartitionStat {
144144
for {
145-
if ctx.Err() != nil {
145+
select {
146+
case <-ctx.Done():
146147
warnings.Add(fmt.Errorf("context cancelled while processing volumes: %w", ctx.Err()))
147148
return partitionStats
149+
default:
148150
}
149151

150152
mounts, err := getVolumePaths(volNameBuf)
@@ -175,17 +177,19 @@ func processVolumeLoop(ctx context.Context, nextVolHandle uintptr, volNameBuf []
175177

176178
func processMountsForVolume(ctx context.Context, mounts []string, processedPaths map[string]struct{}, partitionStats []PartitionStat, warnings Warnings) []PartitionStat {
177179
for _, mount := range mounts {
178-
if ctx.Err() != nil {
180+
select {
181+
case <-ctx.Done():
179182
warnings.Add(fmt.Errorf("context cancelled while processing mount points per volume: %w", ctx.Err()))
180183
return partitionStats
181-
}
182-
if _, ok := processedPaths[mount]; ok {
183-
continue
184-
}
185-
if partitionStat, warning := buildPartitionStat(mount); warning == nil {
186-
partitionStats = append(partitionStats, partitionStat)
187-
} else {
188-
warnings.Add(warning)
184+
default:
185+
if _, ok := processedPaths[mount]; ok {
186+
continue
187+
}
188+
if partitionStat, warning := buildPartitionStat(mount); warning == nil {
189+
partitionStats = append(partitionStats, partitionStat)
190+
} else {
191+
warnings.Add(warning)
192+
}
189193
}
190194
}
191195
return partitionStats

0 commit comments

Comments
 (0)