* 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 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/Y1vHqjKVfQqM3gZy%40basil.wdw.

Reply via email to