Skip to content

Commit e48df7f

Browse files
committed
fileutils: Use ModeType as the mask for mode checks
POSIX provides S_IS*(m) macros to portably interpret the mode type, but does not define values for each type [1]. Alban pointed out that st_mode is not a bitfield on Linux [2]. 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]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html [2]: opencontainers/runtime-tools#308 (comment) [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
1 parent 7d4729f commit e48df7f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fileutils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func CopyFile(source string, dest string) error {
2424
gid := int(st.Gid)
2525

2626
// Handle symlinks
27-
if si.Mode()&os.ModeSymlink != 0 {
27+
if si.Mode()&os.ModeType == os.Symlink {
2828
target, err := os.Readlink(source)
2929
if err != nil {
3030
return err
@@ -76,7 +76,7 @@ func CopyFile(source string, dest string) error {
7676
}
7777

7878
// Chmod the file
79-
if !(si.Mode()&os.ModeSymlink == os.ModeSymlink) {
79+
if !(si.Mode()&os.ModeType == os.ModeSymlink) {
8080
if err := os.Chmod(dest, si.Mode()); err != nil {
8181
return err
8282
}

0 commit comments

Comments
 (0)