1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

Problem with NTFS Hard Links (for Lucene index replication)

Discussion in 'Microsoft News' started by NewsBot, Apr 22, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    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");
     

Share This Page