Added a memory copy to fs.Walk to avoid data races
All checks were successful
/ test (push) Successful in 15s

This commit is contained in:
Eduard Urbach 2025-06-27 11:35:58 +02:00
parent 925fd6ce05
commit ce5416bf91
Signed by: akyoto
GPG key ID: 49226B848C78F6C8

View file

@ -3,6 +3,7 @@
package fs
import (
"strings"
"syscall"
"unsafe"
)
@ -44,16 +45,10 @@ func Walk(directory string, callBack func(string)) error {
continue
}
for i, c := range dirent.Name {
if c != 0 {
continue
}
bytePointer := (*byte)(unsafe.Pointer(&dirent.Name[0]))
name := unsafe.String(bytePointer, i)
callBack(name)
break
}
bytePointer := (*byte)(unsafe.Pointer(&dirent.Name[0]))
name := unsafe.String(bytePointer, 256)
null := strings.IndexByte(name, 0)
callBack(strings.Clone(name[:null]))
}
}