-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: FileMode.String() generates a non-standard Mode representation #27452
Comments
Thank you for reporting this issue @tep and welcome to Go! I'll tag some folks who perhaps might be able to provide some insights into the design decisions or who might be helpful in fixing it |
We're intentionally using a simpler approach to the mode bits, one that hopefully makes some sense on systems like Windows and Plan 9. In any case I don't think we can change this now. It seems sure to break some currently working programs. |
The cross-platform goal is perfectly understandable but, in this case, I don't really think it applies since none of As to code-breakage -- I'd view this in a similar light to the adage that we should never depend on the string value of errors (but, I'm guessing the core Go team sees this differently). Perhaps a minor update for v2? |
Even if we make a v2 of the os package, I can't see us changing this. All the information is available, so people who prefer a different representation can write that themselves. Closing this issue. |
What version of Go are you using (
go version
)?go version go1.11 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/nDV8CK3VVrZ
What did you expect to see?
What did you see instead?
While never explicitly stated in the documentation, the format of the string generated by the os.FileMode
String
method implies that the author's intent is to closely mirror the common mode representation specified by the POSIX 1003.1 man page forls(1)
.With respect to
os.ModeSetuid
,os.ModeSetgid
andos.ModeSticky
- FileMode's String method deviates from the commonly expected behavior. The POSIX standard indicates that the values for these 3 bits are to be rendered as an overlay on the 3 groups of 3 characters that represent the file's permissions. The standard defines this representational behavior as:Instead of following this behavior,
FileMode
displays these values by prepending one or more characters to the 9 character permissions fields. This is the errant behavior.Generating a string representation that, in the most common cases, appears to follow this generally accepted standard -- but then deviates with respect to the
SUID
,SGID
andsticky
bits -- can quickly lead to confusion on the part of the information consumer. This confusion can be eliminated by updating theString
method to represent these bits in a more standard fashion.The text was updated successfully, but these errors were encountered: