Commit 458f01e0 authored by Jakob Unterwurzacher's avatar Jakob Unterwurzacher Committed by Han-Wen Nienhuys

fs: fix Inode.IsDir logic

The file type is not a bitmap, and looking at

	S_IFBLK                          = 0x6000
	S_IFCHR                          = 0x2000
	S_IFDIR                          = 0x4000
	S_IFIFO                          = 0x1000
	S_IFLNK                          = 0xa000
	S_IFREG                          = 0x8000
	S_IFSOCK                         = 0xc000

and confirmed by the added test, we used to classify
block devices and sockets as directories:

 --- FAIL: TestInodeIsDir (0.00s)
     inode_test.go:25: wrong result for case struct { mode uint32; dir bool }{mode:0x6000, dir:false}
     inode_test.go:25: wrong result for case struct { mode uint32; dir bool }{mode:0xc000, dir:false}

The check is fixed now and the test passes.

Change-Id: I6490992d1fecc8a6bea7c2c4b2f1bca765d03d4c
parent bba1094c
...@@ -104,7 +104,7 @@ type Inode struct { ...@@ -104,7 +104,7 @@ type Inode struct {
} }
func (n *Inode) IsDir() bool { func (n *Inode) IsDir() bool {
return n.stableAttr.Mode&syscall.S_IFDIR != 0 return n.stableAttr.Mode&syscall.S_IFMT == syscall.S_IFDIR
} }
func (n *Inode) embed() *Inode { func (n *Inode) embed() *Inode {
......
package fs
import (
"syscall"
"testing"
)
func TestInodeIsDir(t *testing.T) {
cases := []struct {
mode uint32
dir bool
}{
{syscall.S_IFBLK, false},
{syscall.S_IFCHR, false},
{syscall.S_IFDIR, true},
{syscall.S_IFIFO, false},
{syscall.S_IFLNK, false},
{syscall.S_IFREG, false},
{syscall.S_IFSOCK, false},
}
var i Inode
for _, c := range cases {
i.stableAttr.Mode = c.mode
if i.IsDir() != c.dir {
t.Errorf("wrong result for case %#v", c)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment