Thanks for the explanations.After carefully trying again, it is working as expected.
Fabrice2014-06-16 16:55 GMT+02:00 Eli Zaretskii <eliz@gnu.org>:
> From: Fabrice Popineau <fabrice.popineau@gmail.com>
> Date: Mon, 16 Jun 2014 07:30:50 +0000 (UTC)
>
> I tried to use add-name-to-file from elisp,
> which calls w32.c/link(). It seems to end up in doing
> a copy of the file.
No, it doesn't copy. It creates a hard link, as you'd expect.
You can verify this yourself, with the following simple procedure:
. start Dired on some directory
. go to any file in the listing (not a directory: Windows doesn't
support hard links to directories)
. notice that the second column from the left says "1", i.e. this
file has only 1 link to its data
. press H, type the name of a link in the minibuffer and press RET
. press g to refresh the directory listing, and notice that both the
original file and the link now have their link count at 2
. visit the original file, set backup-by-copying-when-linked to a
non-nil value, then modify the file and save it
. visit the link and observe that the same modifications are
"miraculously" present there as well
. still not convinced? type "C-u C-x d", change the switches to say
"-ali", hit RET, and observe that both the file and the link have
the same filesystem index (a.k.a. "inode"), which means they share
the same file data
If you have a decent port of GNU 'ls', you will see the link counts
change there as well.
If you see something different from the above, please describe what
you see.
> I'm fine with that, but that wasn't clear before trying it.
> OTOH if hard links were possible, why not using them? Permissions?
We do use them (on NTFS; on other Windows filesystems you'll likely
get an error).
> Could someone (Eli ?) care to explain why link() is implemented this way?
> Why BackupWrite() is used? I would have expected either CopyFile() or
> CreateHardLink().
CreateHardLink was introduced with Windows 2000, while this code tries
to support older NT systems which lacked that API. Back then this was
the only way to create a hard link. I don't think we still support
NT4 etc., but the code works very well, so I see no reason to rewrite
it using newer APIs.