New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bundle: Implement a DirectoryLoader for fs.FS #3493
bundle: Implement a DirectoryLoader for fs.FS #3493
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! Some nitpicks only. Thanks for contributing. 👍
5a67295
to
23ff632
Compare
@srenatus thank you so much for the review! Code is much cleaner now. The only question left is in regards to the concurrency and if that's something that should be addressed in this PR or not - I don't think we're introducing new behaviour or issues in comparison to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last nitpick :) thanks for bearing with me.
5cf67c9
to
39f8315
Compare
@srenatus added mutex and swapped errors.Wrap to fmt.Errorf :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srenatus should I move this out, while we are at it? 😊
6fe835b
to
866ac9c
Compare
This comment has been minimized.
This comment has been minimized.
f53248d
to
9c76a06
Compare
To make it possible to create a DirectoryLoader based on the fs.FS interface. This interface requires go version 1.16 or above. Fixes: open-policy-agent#3489 Signed-off-by: Simon Gottschlag <simon.gottschlag@xenit.se>
9c76a06
to
3b28f03
Compare
@srenatus do you want me to rebase and force push my branch? |
@simongottschlag thanks, I think we're good here. I've let github update from main, and I'll squash&merge when green. Thanks for your contribution 🚀 |
} | ||
|
||
fileName := d.files[d.idx] | ||
d.idx++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This incrementing is the only bit of this method that needs to be synchronized. Thus, it is probably better to use atomic.AddUint32
since that will avoid the mutex alltogether. In order for this to work, the addition must go at the top of the method, before it is used.
sync.Mutex | ||
filesystem fs.FS | ||
files []string | ||
idx int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: array indices cannot be negative, so this should be a uint.
@bittrance good points, feel free to do a follow-up 😉 |
To make it possible to create a DirectoryLoader based on the fs.FS interface.
This interface requires go version 1.16 or above.
Fixes: #3489
Signed-off-by: Simon Gottschlag simon.gottschlag@xenit.se