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

os: document Chown behavior when uid == -1 or gid == -1 #24710

Closed
mark-rushakoff opened this issue Apr 5, 2018 · 4 comments
Closed

os: document Chown behavior when uid == -1 or gid == -1 #24710

mark-rushakoff opened this issue Apr 5, 2018 · 4 comments

Comments

@mark-rushakoff
Copy link
Contributor

@mark-rushakoff mark-rushakoff commented Apr 5, 2018

What version of Go are you using (go version)?

https://golang.org/pkg/os/

Does this issue reproduce with the latest release?

Yes, checked tip docs as well: https://tip.golang.org/pkg/os/ (Build version devel +d3026dd30a Thu Apr 5 18:54:31 2018 +0000.)

What did you do?

I read some code like os.Chown(path, -1, gid) and was unsure what uid == -1 meant, so I checked the docs.

What did you expect to see?

Explanation of behavior when uid == -1 (for any of Chown, Lchown, and (*File).Chown).

What did you see instead?

I had to trace through the os code to learn that it calls syscall.Chown, then I had to check man 2 chown to learn:

One of the owner or group id's may be left unchanged by specifying it as -1.

I also consulted http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html which states

If owner or group is specified as (uid_t)-1 or (gid_t)-1, respectively, the corresponding ID of the file shall not be changed.

so I believe this behavior should be okay to add to Godoc.

@bradfitz bradfitz added the NeedsFix label Apr 6, 2018
@bradfitz bradfitz added this to the Go1.11 milestone Apr 6, 2018
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Apr 6, 2018

@ianlancetaylor, this is news to me that we do this (by accident?). Are we trying to be POSIX-ish here, or did that just happen?

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Apr 6, 2018

NeedsFix because we need to document it either way. But we need to decide which way.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 11, 2018

That's how POSIX works. Passing the owner or group as -1 leaves it unchanged. I note that we don't implement this feature on NaCl. On Windows and Plan 9 we don't implement Chown at all. So I think we should implement it in NaCl and document it in the os package.

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 11, 2018

Change https://golang.org/cl/106464 mentions this issue: os: document that Chown with -1 means to leave values unchanged, like POSIX

@gopherbot gopherbot closed this in 044d2d5 Apr 11, 2018
@golang golang locked and limited conversation to collaborators Apr 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.