Skip to content

Commit dfd7f35

Browse files
committed
os: add ModeIrregular flag
There is currently no way for os.FileMode.IsRegular to report false without being one of the following types: ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice This makes it difficult for custom implementations of os.FileInfo to return a Mode that is explicitly not regular without resorting to setting one of the types listed above. However, every one of the aforementioned types are ill-suited as a general-purpose "not regular" file type. Thus, add a ModeIrregular to serve exactly for that purpose. The ModeIrregular type carries no information other than the fact that the file is not regular. Updates #22903 Fixes #23878 Change-Id: I4f34d88f960bcb014816d8e7b5de8b1035077948 Reviewed-on: https://go-review.googlesource.com/94856 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 4b265fb commit dfd7f35

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/os/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ const (
5454
ModeSetgid // g: setgid
5555
ModeCharDevice // c: Unix character device, when ModeDevice is set
5656
ModeSticky // t: sticky
57+
ModeIrregular // ?: non-regular file; nothing else is known about this file
5758

5859
// Mask for the type bits. For regular files, none will be set.
59-
ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice
60+
ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeIrregular
6061

6162
ModePerm FileMode = 0777 // Unix permission bits
6263
)
6364

6465
func (m FileMode) String() string {
65-
const str = "dalTLDpSugct"
66+
const str = "dalTLDpSugct?"
6667
var buf [32]byte // Mode is uint32.
6768
w := 0
6869
for i, c := range str {

0 commit comments

Comments
 (0)