[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: w32.c/link()

From: Fabrice Popineau
Subject: Re: w32.c/link()
Date: Mon, 16 Jun 2014 20:48:14 +0200

I have found my problem.

I did what Eli said and it is working as expected.
But now I start again :

emacs -Q

M-: (add-name-to-file "c:/temp/foo.el" "c:/temp/foo1.el" t)

M-x c:/temp/foo.el
add a few characters
C-x s
M-x dired

And foo.el size has changed, but not foo1.el size.

This is because after editing foo.el, foo1.el is still a hard link but to foo.el~ (autosave file). :-/
Quite misleading! Sorry for the noise.


2014-06-16 19:55 GMT+02:00 Fabrice Popineau <address@hidden>:
Thanks for the explanations.
After carefully trying again, it is working as expected.


2014-06-16 16:55 GMT+02:00 Eli Zaretskii <address@hidden>:

> From: Fabrice Popineau <address@hidden>
> 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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]