From: Jeremy Maitin-Shepard (jbms_at_[hidden])
Date: 2003-11-30 02:02:21
I wrote some code to show how hard link support could be added to the
boost.filesystem library. It is included in the attached patches.
The patches add three functions to operations.hpp and
bool equivalent(path const &lhs, path const &rhs);
Tests if the two arguments refer to the same file. This is useful even
outside the context of hard links, since it avoids the problem of
having to compare paths syntactically. Throws if either of the paths
does not exist or is inaccessible.
unsigned int link_count(path const &ph);
Returns the number of hard links to the file specified by the
argument. (On platforms that do not support hard linking, this always
returns 1.) Throws if the path does not exist or is inaccessible.
void link(path const &existing_path, path const &new_path);
Creates a hard link from `new_path' to the file referred to by
`existing_path'. Throws if `existing_path' does not exist, if
`new_path' does exist, or if the operation fails for any of a variety
Note that the code in the attached patches has not been tested on
Windows, and due to the use of CreateHardLink, it may be the case that
it does not compile or run on versions of Windows older than Windows
It would be convenient if there were a way to provide a unique
identifier for a file, for use in an associative container.
Unfortunately, although Windows does provide a 64-bit identifier for a
file, the documentation indicates that these identifiers are only valid
while there is an open handle to the file. I suppose it would be
possible to keep an open handle to the file as part of the identifier,
but such a system seems highly resource intensive.
-- Jeremy Maitin-Shepard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk