-
Notifications
You must be signed in to change notification settings - Fork 110
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
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.
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 { |
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.
We want to change permissions on the TempFile
, f
, we have created above rather than the filename
passed to the function:
if err = os.Chmod(filename, perm); err != nil { | |
if err = os.Chmod(f.Name(), perm); err != nil { |
Note 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. |
Thanks for sharing that!
The function is only used twice:
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. |
@joshuagl are you happy with the new changes? |
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.
@melaurent - Do you think you can update the commit message?
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) | ||
} | ||
|
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.
Is that relevant to the windows compatibility PR?
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.
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
The f.Chmod method causes an error on windows