Skip to content

Commit

Permalink
runtimetest: Use ModeType as the mask in the symlink check
Browse files Browse the repository at this point in the history
We've been using ModeSymlink as the mask since the check landed in
da25004 (runtimetest: add linux default symbolic link validation,
2016-11-30, #284).  POSIX provides S_IS*(m) macros to portably
interpret the mode type, but does not define values for each type [2].
Alban pointed out that st_mode is not a bitfield on Linux [1].  For
example, Linux defines [3]:

  S_IFBLK 060000
  S_IFDIR 040000
  S_IFCHR 020000

So 'm&S_IFCHR == S_IFCHR', for example, would succeed for both
character and block devices.  Go translates the system values to a
platform-agnostic bitfield [4], so the previous approach works on Go.
But it may be confusing for people used to the native non-bitfield
mode, so this commit moves us to an approach that does not rely on
Go's using a bitfield.

[1]: #308 (comment)
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
[3]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/stat.h?h=v4.16#n9
[4]: https://github.com/golang/go/blob/b0d437f866eb8987cde7e6550cacd77876f36d4b/src/os/types.go#L45

Signed-off-by: W. Trevor King <[email protected]>
  • Loading branch information
wking committed Apr 6, 2018
1 parent 990e267 commit 92de75c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func (c *complianceTester) validateDefaultSymlinks(spec *rspec.Spec) error {
continue
}

isSymlink := fi.Mode()&os.ModeSymlink == os.ModeSymlink
isSymlink := fi.Mode()&os.ModeType == os.ModeSymlink
rfcError, err = c.Ok(
isSymlink,
specerror.DefaultRuntimeLinuxSymlinks,
Expand Down

0 comments on commit 92de75c

Please sign in to comment.