Opened 5 years ago

#13428 new Bugs

Windows: "is_symlink" for drive letter (without trailing directory separator) returns the wrong result

Reported by: m.kosch@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.66.0 Severity: Problem
Keywords: symlink is_symlink canonical weakly_canonical GetFileAttributes GetFileAttributesW Cc: m.kosch@…

Description

Suppose you have a normal directory Dir and a symlink named SymlinkToDir which points to Dir on drive C:\.

The following two tests lead to different results:

boost::filesystem::path fsPathToSymlink("C:\\SymlinkToDir");
boost::filesystem::path fsPathToDrive("C:");

current_path(fsPathToDrive + "\\");
bool b1 = is_symlink(fsPathToDrive);
assert( b1 == false );

current_path(fsPathToSymlink);
bool b2 = is_symlink(fsPathToDrive);
assert( b2 == true );

It seems that Windows differentiates between C: and C:\. The first form seems to denote the current directory on drive C:\ while the second form seems to denote drive C:\ itself. This also can be observed in the Windows command promt.

is_symlink internally uses GetFileAttributesW to determine the symlink status. GetFileAttributes("C:") returns the file attributes of C:\\SymlinkToDir instead of C:\.

The function is_symlink is used to implement other functions, so this problem also effects at least the following other functions, possibly even many more:

  • canonical returns BOOST_ERROR_NOT_SUPPORTED for an absolute path, if compiled for Windows versions earlier than Windows Vista (_WIN32_WINNT < 0x0600) and the current directory represents a symlink.
  • weakly_canonical in the same scenario as above, because this utilizes canonical.

Change History (0)

Note: See TracTickets for help on using tickets.