pin: make WalkDir harder to misuse and add Windows support#1736
pin: make WalkDir harder to misuse and add Windows support#1736lmb merged 1 commit intocilium:mainfrom
Conversation
|
@mtardy could you take a look whether this still fits your usecase in tetragon? |
will take a look shortly 👀 , was busy conferencing... |
Looks good, am I using it correctly cilium/tetragon@38c1109 ? |
|
Yeah those changes look good! You can pass |
ah yeah it seems
ah yeah maybe indeed |
The current WalkDir API requires the user to close each object that is iterated over. This isn't very intuitive, the two uses of the function in the tetragon code base end up leaking objects. It's also not straight forward to implement WalkDir on Windows, since BPFFS isn't really a thing on that platform. Instead, turn WalkDir into an iterator which returns a new Pin object. By default, objects are closed once they have been iterated over. The user may call Pin.Take if they wish to retain the object. This is similar to the existing link.Iterator.Take. One downside is that directories are not returned by the iteration anymore. The existing code in tetragon doesn't use them and is therefore not affected. There is also no more fine grained control over whether to descent into a directory. Aborting an iteration is still supported and as efficient as before. Fixes: cilium#1652 Signed-off-by: Lorenz Bauer <[email protected]>
mtardy
left a comment
There was a problem hiding this comment.
I like this new version when using the iter with existing for := range.
The current WalkDir API requires the user to close each object that is iterated over. This isn't very intuitive, the two uses of the function in the tetragon code base end up leaking objects. It's also not straight forward to implement WalkDir on Windows, since BPFFS isn't really a thing on that platform.
Instead, turn WalkDir into an iterator which returns a new Pin object. By default, objects are closed once they have been iterated over. The user may call Pin.Take if they wish to retain the object. This is similar to the existing link.Iterator.Take.
One downside is that directories are not returned by the iteration anymore. The existing code in tetragon doesn't use them and is therefore not affected. There is also no more fine grained control over whether to descent into a directory. Aborting an iteration is still supported and as efficient as before.
Fixes: #1652