Skip to content
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

Merged

Conversation

simongottschlag
Copy link
Contributor

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

Copy link
Contributor

@srenatus srenatus left a 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. 👍

bundle/filefs.go Show resolved Hide resolved
bundle/filefs.go Outdated Show resolved Hide resolved
bundle/filefs.go Outdated Show resolved Hide resolved
bundle/filefs.go Outdated Show resolved Hide resolved
bundle/filefs.go Outdated Show resolved Hide resolved
bundle/filefs.go Outdated Show resolved Hide resolved
bundle/filefs.go Outdated Show resolved Hide resolved
@simongottschlag simongottschlag force-pushed the feature/bundle/NewFSLoader branch 2 times, most recently from 5a67295 to 23ff632 Compare May 27, 2021 21:14
@simongottschlag
Copy link
Contributor Author

@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 NewDirectoryLoader().

srenatus
srenatus previously approved these changes May 28, 2021
Copy link
Contributor

@srenatus srenatus left a 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.

bundle/filefs.go Outdated Show resolved Hide resolved
@simongottschlag
Copy link
Contributor Author

@srenatus added mutex and swapped errors.Wrap to fmt.Errorf :)

Copy link
Contributor Author

@simongottschlag simongottschlag left a 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? 😊

bundle/filefs.go Outdated Show resolved Hide resolved
@simongottschlag

This comment has been minimized.

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>
@simongottschlag
Copy link
Contributor Author

@srenatus do you want me to rebase and force push my branch?

@srenatus
Copy link
Contributor

@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 🚀

@srenatus srenatus merged commit 32ee3b7 into open-policy-agent:main May 31, 2021
@simongottschlag simongottschlag deleted the feature/bundle/NewFSLoader branch May 31, 2021 08:54
}

fileName := d.files[d.idx]
d.idx++
Copy link
Contributor

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
Copy link
Contributor

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.

@srenatus
Copy link
Contributor

srenatus commented Jun 1, 2021

@bittrance good points, feel free to do a follow-up 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function to read files from fs.FS to create bundle
3 participants