Added a memory copy to fs.Walk to avoid data races
All checks were successful
/ test (push) Successful in 15s
All checks were successful
/ test (push) Successful in 15s
This commit is contained in:
parent
925fd6ce05
commit
ce5416bf91
1 changed files with 5 additions and 10 deletions
|
@ -3,6 +3,7 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -44,16 +45,10 @@ func Walk(directory string, callBack func(string)) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range dirent.Name {
|
bytePointer := (*byte)(unsafe.Pointer(&dirent.Name[0]))
|
||||||
if c != 0 {
|
name := unsafe.String(bytePointer, 256)
|
||||||
continue
|
null := strings.IndexByte(name, 0)
|
||||||
}
|
callBack(strings.Clone(name[:null]))
|
||||||
|
|
||||||
bytePointer := (*byte)(unsafe.Pointer(&dirent.Name[0]))
|
|
||||||
name := unsafe.String(bytePointer, i)
|
|
||||||
callBack(name)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue