On Sat Mar 8 13:58:45 2025 +0000, Jinoh Kang wrote:
Better open the destination file's directory instead of the source file's directory.
- We may only have search access to src directory but not read access (--x).
- `O_PATH` is only available on Linux-like OSes. `O_SEARCH` is also not
cross platform. Notably, macOS lacks `O_PATH`. To achieve this, we can switch the order: do stat() on src dirname, and open/fstat on dest dirname. If different directories, it must be a hardlink, so we simply remove the source and bail out. If the same, switching order did nothing, and we can proceed as normal.
Yeah, I hadn't realized that possibility, although probably rare in practice. I probably used this order so I can use `unlinkat` when removing the source, but it doesn't really matter, I'll swap.