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

fix: chmod windows compatible #131

Closed
wants to merge 4 commits into from

Conversation

gosthell
Copy link

@gosthell gosthell commented May 5, 2021

The f.Chmod method causes an error on windows

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @melaurent! Apologies for the long delay in getting a response to you, we recently added some new maintainers to the project and things are much more active here now.

Are you using go-tuf on Windows devices? We should probably update our CI to include a Windows builder in order to catch issues like this in future.

util/util.go Outdated
@@ -280,7 +280,7 @@ func AtomicallyWriteFile(filename string, data []byte, perm os.FileMode) error {
return err
}

if err = f.Chmod(perm); err != nil {
if err = os.Chmod(filename, perm); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to change permissions on the TempFile, f, we have created above rather than the filename passed to the function:

Suggested change
if err = os.Chmod(filename, perm); err != nil {
if err = os.Chmod(f.Name(), perm); err != nil {

@zwass
Copy link
Contributor

zwass commented Oct 3, 2021

Note that os.Chmod doesn't work as one might expect on Windows (see https://pkg.go.dev/os#Chmod):

On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file.

I'm not sure what the context is for the permission settings in this part of the code, but this may require some other strategy.

@joshuagl
Copy link
Member

joshuagl commented Oct 4, 2021

Note that os.Chmod doesn't work as one might expect on Windows (see https://pkg.go.dev/os#Chmod):

On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file.

Thanks for sharing that!

I'm not sure what the context is for the permission settings in this part of the code, but this may require some other strategy.

The function is only used twice:

  1. writing metadata files rw/r/r (0644)
  2. writing private keys with rw/-/- (0600)

This change alone is not enough to make tests pass on Windows, but I'd be happy to land it as a partial fix and create an Issue for Windows support where we can figure out what to do with i.e. permissions if there's someone who wants to do the work or a strong desire from users.

@trishankatdatadog
Copy link
Member

@joshuagl are you happy with the new changes?

Copy link
Contributor

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melaurent - Do you think you can update the commit message?

@gosthell gosthell closed this Feb 10, 2022
Comment on lines +650 to +668
func (r *Repo) Root() error {
return r.RootWithExpires(data.DefaultExpires("root"))
}

func (r *Repo) RootWithExpires(expires time.Time) error {
if !validExpires(expires) {
return ErrInvalidExpires{expires}
}

root, err := r.root()
if err != nil {
return err
}

root.Expires = expires

return r.setMeta("root.json", root)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that relevant to the windows compatibility PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's not, I pushed on master and I forgot I still had this open. I closed it I'm done with this lib

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.

5 participants