os: FileMode.String() generates a non-standard Mode representation #27452
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
v2
An incompatible library change
Milestone
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: