Thank you very much On Fri, Oct 28, 2022, 8:15 AM Marvin Renich <m...@renich.org> wrote:
> * Robert Solomon <drrob...@gmail.com> [221028 07:36]: > > On ubuntu 22.04, I would like the walk function to NOT follow symlinks > to > > other filesystems. The find command uses the -xdev switch to achieve > this. > > > > How can I get walk to behave like the -xdev switch to find? > > On Linux: > > ---- getdevid_linux.go > > package main > > import ( > "io/fs" > "syscall" > ) > > type DevId uint64 > > // GetDevice returns the Device ID on which the given file resides. > func GetDevice(path string, fi fs.FileInfo) DevId { > var stat = fi.Sys().(*syscall.Stat_t) > return DevId(stat.Dev) > } > > ---- > > Then before calling filepath.Walk, filepath.WalkDir (more efficient), or > fs.WalkDir, obtain the device ID of the root. In the call to WalkDir, > pass this device ID to your walk function: > > err = filepath.WalkDir(root, func(path string, d fs.DirEntry, err > error) error { return MyWalkFn(devId, path, d, err) }) > > In MyWalkFn, use d to obtain the device ID of the current path, and > return fs.SkipDir if the device IDs do not match. > > ...Marvin > > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/sBHhJydS66w/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/Y1vHqjKVfQqM3gZy%40basil.wdw > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJTu_tYofRrP-5PJ8%2BjJvDV8kBmAACHOU5FnYiKTq%2B0oUpJE%2Bg%40mail.gmail.com.