Skip to content

TestStat: dirNlinkIncludesDot should not necessarily be true #2409

@QuLogic

Description

@QuLogic

Describe the bug
The number of hard links seems to be defined by the file system. So dirNlinkIncludesDot, which is always true on Linux, is not correct, and causes TestStat to fail sometimes. Instead of hard-coding numbers, it may be best to just start with the existing count on an empty directory, and then check differences when adding/removing files.

To Reproduce
Run tests with a btrfs temporary directory, e.g.,

$ TMPDIR=/path/to/btrfs/directory go test ./internal/sysfs
--- FAIL: TestStat (0.00s)
    --- FAIL: TestStat/empty_dir (0.00s)
        require.go:331: expected 2, but was 1: linux
            .../wazero/internal/sysfs/stat_test.go:46
    --- FAIL: TestStat/not_empty_dir (0.00s)
        require.go:331: expected 3, but was 1: linux
            .../wazero/internal/sysfs/stat_test.go:72

and for example, on a btrfs filesystem an empty directory has 1 Link:

$ mkdir foo
$ stat foo
  File: foo
  Size: 0         	Blocks: 0          IO Block: 4096   directory
Device: 0,43	Inode: 183574674   Links: 1
Access: (0755/drwxr-xr-x)  Uid: ( )   Gid: ( )
Context: unconfined_u:object_r:container_file_t:s0
Access: 2025-07-21 05:23:03.222367693 -0400
Modify: 2025-07-21 05:23:03.222367693 -0400
Change: 2025-07-21 05:23:03.222367693 -0400
 Birth: 2025-07-21 05:23:03.222367693 -0400

whereas on /tmp, which is tmpfs, an empty directory has 2 Links:

$ mkdir /tmp/foo
$ stat /tmp/foo
  File: /tmp/foo
  Size: 40        	Blocks: 0          IO Block: 4096   directory
Device: 0,40	Inode: 89168       Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( )   Gid: ( )
Context: unconfined_u:object_r:user_tmp_t:s0
Access: 2025-07-21 05:24:24.626843648 -0400
Modify: 2025-07-21 05:24:24.626843648 -0400
Change: 2025-07-21 05:24:24.626843648 -0400
 Birth: 2025-07-21 05:24:24.626843648 -0400

Expected behavior
Tests should pass.

Environment (please complete the relevant information):

  • Go version: go version go1.24.4 linux/amd64
  • wazero Version: v1.9.0
  • Host architecture: amd64
  • Runtime mode: n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions