Jump to content

Recommended Posts

Posted

Hi, am using NTFS hard links to do Lucene index replication.* I'm not sure why, but seems like if I make a hard link to a file with CreateHardLink API (from kernel32), then if I subsequently open the original file for reading, I cannot delete the hard link with DeleteFile or with File.Delete from .NET.* It fails with "file is locked by another process" error.* But according to MSDN, DeleteFile should work since it is just decrementing count of hard links not actually deleting the file.

 

Here is code to reproduce...

 

Assume test.txt exists already...

 

// create new hard link "testHL.txt" pointing to original file...

CreateHardLink("testHL.txt","test.txt",IntPtr.Zero);

 

// open text.txt for reading, but now I cannot delete hard link...

using(StreamReader r=new StreamReader("test.txt"))

{

* *** string c=r.ReadLine();

*** * File.Delete("testHL.txt");

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...