Editing the hardlink doesn't edit the original file

3

I have a file at D:\JavaScript\CheckIban.js, and I want to reuse it in many places without duplicating it. Because when I fix a bug (change its content) I need that change to be propagated to all files. Using links my plan is to change one instance of the hardlinks, and expect other instances to be updated automatically.

Now, let's say that I've create a hardlink to this file using:

mklink /H D:\Projects\Crm\Site\Scripts\CheckIban.js D:\JavaScript\CheckIban.js

and I get the success message that the hardlink is created for ...

However, when I open each file and change it, the content of the other file is not changed. What do I miss here?

Notes: I can't use soft links, because I'm using a program (TFS) that doesn't support working with soft links.

Saeed Neamati

Posted 2015-04-29T06:12:44.080

Reputation: 1 403

Use fsutil hardlink list D:\JavaScript\CheckIban.js to verify that the hard link still exists. – Chirag Bhatia - chirag64 – 2015-04-29T06:23:04.480

@Chirag64, I ran that command and only the file itself got listed. What might be wrong? – Saeed Neamati – 2015-04-29T06:43:34.463

The command is correct, you are sure that the folder you have chosen is correct? There is nothing odd about the target folder? The file doesn't already exist in the target location? A permissions issue? Have you tried running the command from an admin cmd prompt? – Julian Knight – 2015-04-29T07:37:40.013

1Actually the target is not a folder, it's a file. And yeah, I did everything right. File doesn't exist (I do it manually and delete it before recreating), no permission issue because I'm admin and cmd is run under admin permissions, otherwise mklink would throw error. – Saeed Neamati – 2015-04-29T08:09:01.460

@SaeedNeamati Did you ever figure this out? I've got the same stupid issue... – Nick Spreitzer – 2017-03-16T00:32:07.610

Answers

3

There's a difference between changing the file and replacing the file. According to this Microsoft page on Hard Links and Junctions, "Any changes to that file are instantly visible to applications that access it through the hard links that reference it." However, consider what happens when you replace a file: the file system deletes the file (in this case the hard link), then writes the new file with the same path and file name as the former hard link.

So it depends on how the program you're using to change the file writes to the file system when it updates the file.

See also What operations breaks the hardlinks

GlennFromIowa

Posted 2015-04-29T06:12:44.080

Reputation: 591