johnmehr / gitup

A minimalist, dependency-free FreeBSD program to clone/pull Git repositories.
BSD 2-Clause "Simplified" License
50 stars 9 forks source link

Add fix for when readdir(directory) d_type value is always 0 #67

Closed johnmehr closed 3 years ago

johnmehr commented 3 years ago

The d_type value set by the readdir(directory) call in prune_tree() on FreeBSD 11-STABLE r369614 with a ZFS filesystem is always returning 0.

ronaldklop commented 3 years ago

See https://lists.freebsd.org/pipermail/freebsd-fs/2021-April/028964.html and replies.

The manual page dirent(5) says: "BUGS The usage of the member d_type of struct dirent is unportable as it is FreeBSD-specific. It also may fail on certain file systems, for example the cd9660 file system. "

I think gitup would be more standards compliant if it used stat(2) for determining the type of a file/dir. If d_type == DT_UNKNOWN (0) it could stat(2) the path and check st_mode. So the d_type is an optimized code path, but it fallbacks to an extra syscall on filesystems that need it.

johnmehr commented 3 years ago

Thank you for digging and finding the root of the problem. Nick sent me a patch to use stat(2) instead and I believe it's working properly now. Thanks!