develooper Front page | perl.perl5.porters | Postings from December 2003

Re: [PATCH] Re: perl @ 21830

Thread Previous | Thread Next
From:
Jody Belka
Date:
December 4, 2003 03:36
Subject:
Re: [PATCH] Re: perl @ 21830
Message ID:
44305.81.168.23.49.1070537770.squirrel@zeus.aardvark-ss.com
Steve Hay said:
> Rafael Garcia-Suarez wrote:
>>Depends. How can we test if two files are identical, link()-wise,
>>on MSWin32 ? If we can test it, we should fix Copy.pm by adding
>>another branch to the if() :
>>    elsif ($^O eq 'MSWin32' && $Config{d_link}) {...}
>>If we can't, we should fix the test so it's skipped on Windows.
>>
> I can't think of any way to test it.  File::Copy uses the inode on other
> platforms to test hardlinks, but this is always returned as 1 on
> MSWin32.  The Microsoft documentation for stat() notes: "The inode, and
> therefore st_ino, has no meaning in the FAT, HPFS, or NTFS file systems."

There is a way to test this on windows. Basically, you have to get file
handles for both files using CreateFile, and then call
GetFileInformationByHandle on both of them. This function returns a
pointer to a BY_HANDLE_FILE_INFORMATION structure which contains three
important members:

dwVolumeSerialNumber
    Serial number of the volume that contains the file.

nFileIndexHigh
    High-order part of a unique identifier associated with the file.

nFileIndexLow
    Low-order part of a unique identifier associated with the file.

To quote on FileIndex from the BY_HANDLE_FILE_INFORMATION reference,

[[
Note that this value is useful only while the file is open by at least one
process. If no processes have it open, the index may change the next time
the file is opened.

The identifier (low and high parts) and the volume serial number uniquely
identify a file on a single computer. To determine whether two open
handles represent the same file, combine this identifier and the volume
serial number for each file and compare them.
]]


References for all of the above:

CreateFile - http://xrl.us/CreateFile
GetFileInformationByHandle - http://xrl.us/GetFileInformationByHandle
BY_HANDLE_FILE_INFORMATION - http://xrl.us/ByHandleFileInformation


HTH

-- 
Jody Belka
knew (at) pimb (dot) org

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About