Description
The protected_hardlinks
kernel option prevents hard linking to files you don't own.
Downstream applications (like https://github.com/apache/kvrocks) call LinkFile directly; they can benefit from knowing whether a hardlink failed because of protected_hardlinks
, and fall-back to a less efficient recursive copy.
Some other concerns to keep in mind for a fully correct fix: a naive approach would be to read the /proc/sys/fs/protected_hardlinks
file if a LinkFile
permission error occurs, and return EPERM if it reads '1'.
However, on older Linux kernels (5.x), this file is not world-readable, so we should perhaps assume that protected_hardlinks
is enabled for these machines.
I've also posted a partial fix here which solves most of the issue but fails to address the possibility that the file is unreadable.