gulrak / filesystem

An implementation of C++17 std::filesystem for C++11 /C++14/C++17/C++20 on Windows, macOS, Linux and FreeBSD.
MIT License
1.34k stars 173 forks source link

Error in test "30.10.15.15 hard_link_count" #97

Closed phprus closed 3 years ago

phprus commented 3 years ago

Describe the bug hard_link_count test logic is wrong on BTRFS. The links counter is always equal to 1 (https://unix.stackexchange.com/a/618726).

Error:

40: /home/.../3rdparty/ghc-filesystem/src/test/filesystem_test.cpp:2037: FAILED:
40:   CHECK( fs::hard_link_count(t.path()) == 2 )
40: with expansion:
40:   1 == 2
40:
40: /home/.../3rdparty/ghc-filesystem/src/test/filesystem_test.cpp:2039: FAILED:
40:   CHECK( fs::hard_link_count(t.path()) == 3 )
40: with expansion:
40:   1 == 3

To Reproduce Run test on BTRFS.

phprus commented 3 years ago

Btrfs is are default file system on SUSE 12+ and Fedora 33+.

Possible workaround: Replace CHECK(fs::hard_link_count(t.path()) == 2) to CHECK(fs::hard_link_count(t.path()) == 2 || fs::hard_link_count(t.path()) == 1); and CHECK(fs::hard_link_count(t.path()) == 3) to CHECK(fs::hard_link_count(t.path()) == 3 || fs::hard_link_count(t.path()) == 1);

gulrak commented 3 years ago

Nice find. Ich think I prefer to use an lstat helper in filesystem_test for Linux to compare to its result, to keep the test from accepting 1 when the fs is not BTRFS. I'll look into it later today after work.

gulrak commented 3 years ago

This is now part of release v1.5.2