Merge pull request #1430 from davidnewhall/master

Fix 'send on closed channel' bug with windows disks
pull/1433/head
shirou 2 years ago committed by GitHub
commit 27c8bfae7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ import (
"bytes"
"context"
"fmt"
"sync"
"syscall"
"unsafe"
@ -90,12 +91,20 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
var ret []PartitionStat
retChan := make(chan []PartitionStat)
errChan := make(chan error)
defer close(retChan)
defer close(errChan)
lpBuffer := make([]byte, 254)
var waitgrp sync.WaitGroup
waitgrp.Add(1)
defer waitgrp.Done()
f := func() {
defer func() {
waitgrp.Wait()
// fires when this func and the outside func finishes.
close(errChan)
close(retChan)
}()
diskret, _, err := procGetLogicalDriveStringsW.Call(
uintptr(len(lpBuffer)),
uintptr(unsafe.Pointer(&lpBuffer[0])))

Loading…
Cancel
Save