On Sat Nov 16 10:41:24 2024 +0000, Jinoh Kang wrote:
Suppose `foo.txt` and `bar.txt` are hard links to the same file. What happens if we link `foo.txt` to `bar.txt` with `FILE_LINK_REPLACE_IF_EXISTS`? In your code, `different_case = 1` for completely different names too (foo ≠ bar), but I'm not sure this is renaming the file (deleting `foo.txt`) on Windows as well.
Thanks for the review, I had forgotten about this (well, with year end I'd probably look through my stuff again).
Good point. Note that `different_case` should be 1 only when the case is different on the name, but the "name" here is always the destination. The "source" is just a fd. Maybe this is not clear, I should add a comment.
So for your question, the behavior is the same as before, because you have a fd to `foo.txt` and then you want to rename it to `bar.txt` (which is already a hardlink to the same file), but in this case the "name" and "case" are the same, both are `bar.txt` so `different_case = 0`.
However, if we were to rename it to `Bar.txt` (while `bar.txt` already exists, lowercase), then `different_case = 1`. In this case we'd try to rename `foo.txt` to `Bar.txt`.
This is… bad I guess, because now we'd have both `Bar.txt` and `bar.txt` in the same directory (but both are hardlinks to the same file).
Any idea how to **detect** this? And apply appropriate fix (depending what happens on Windows).