Closed tep closed 1 year ago
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 /cc @rsc @bradfitz @ianlancetaylor @ericlagergren
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 ModeSetuid
, ModeSetgid
or ModeSticky
are referenced by any of the Windows or Plan9 specific code. Changing the representation of these values would have no impact on those systems and, as far as I know, all remaining supported operating systems would benefit (since they are supposed to be POSIX compliant).
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.