-
Notifications
You must be signed in to change notification settings - Fork 592
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
[gfd] Fixing logic of atomically file writing #792
Conversation
What do you think about using github.com/google/renameio instead of our own implementation of atomic file writing? import "github.com/google/renameio"
func writeFileAtomically(path string, contents []byte, perm os.FileMode) error {
return renameio.WriteFile(path, contents, perm)
} github.com/google/renameio is stable, has no dependencies, is quite popular (used by 4.3k), and performs its task well. |
@belo4ya thanks for the fix. I think we would be ok with using |
5857ab0
to
e4fdcba
Compare
Done. I replaced the function The only thing is, the temporary file will be created in |
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.
Thanks for this fix @belo4ya.
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.
With regards to:
The only thing is, the temporary file will be created in $TMPDIR instead of /etc/kubernetes/node-feature-discovery/features.d/gfd-tmp/ (I don't think this is a problem, but it's worth mentioning).
Let's squash these two commits into a single commit and include this note in the commit message along with additional context on the fixed bug (something like your description would be great).
275a44d
to
a608f7f
Compare
@elezar, done. |
fix NVIDIA#791 Corrected the incorrect order of operations in atomic writing of the feature file, which could lead to a "permission denied" error observed in the nfd-worker logs note: now the temporary file is created in $TMPDIR instead of /etc/kubernetes/node-feature-discovery/features.d/gfd-tmp/ Signed-off-by: belo4ya <41exey.kov41ev@gmail.com>
a608f7f
to
442edd4
Compare
fix #791
The current implementation of the writeFileAtomically function contains a bug - the
os.Chmod
function is called afteros.Rename
, causing a moment when the target file (features.d/gfd
) has incorrect permissions (0600
instead of0644
):To fix this issue, the order of the calls needs to be changed to:
os.Chmod -> os.Rename