* EricR <butzwon...@gmail.com> [181004 13:33]: > Hi! I'm new to Go and need to do something with each file in directories. > Symlinks need to be followed. I've tried filepath and a few popular > libraries and they either crash with segfaults on my system, do not follow > symlinks or do not prevent infinite loops. > > Is there a directory walking library that follow symlinks but detects > cylces as you would expect? It needs to work on all platforms.
I would use filepath.Walk with a WalkFunc that checked FileInfo.Mode() for a symlink, used os.Stat() to determine if the symlink points to a directory, and if it does, calls Walk with the symlink target. Preventing loops is as simple as making the WalkFunc a closure with a map[string]struct{} that keeps track of every directory already walked. If the current path is a directory and is in your map, exit, otherwise (for directories) add the directory to the map and continue. It is not a lot of work on top of Walk to get what you want. If you need more help, let me know. ...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. For more options, visit https://groups.google.com/d/optout.