Opened 9 years ago

Last modified 7 years ago

#9824 assigned Bugs

boost::filesystem::is_empty() doesn't work with symlinks on Windows

Reported by: michael.burr@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.56.0 Severity: Regression
Keywords: Cc:

Description

See the original information on this problem in this Stackoverflow question:

hxxp://stackoverflow.com/questions/22668337/boostfilesystemis-empty-returns-false-for-symlinks

The person who reported that problem/asked the question on Stackoverflow also set up a github project that demonstrates the problem:

hxxps://github.com/monsdar/BoostSymLinkError

Basically, the filesystem::is_empty() function doesn't follow a symlink, so it will return false even if the target of the symlink has a length greater than 0.

The V2 filesystem library worked for this situation. The difference is that V2 used the stat() function in the VC++ library, while the V3 filesystem library uses the Win32 GetFileAttributesExW() API. The latter does not follow symlinks and returns a file size of 0 regardless of the size of the symlink target.

Attached is a diff for libs/filesystem/src/operations.cpp which uses the stat() technique very similar to what was used in filesystem V2. A few differences:

  • _wstat() is used instead of stat() to accommodate UNICODE filenames
  • a bit test using _S_IFDIR is used to determine if the path is a directory instead of S_ISDIR() because the VC++ library doesn't include a S_ISDIR() or _S_ISDIR() macro.

This patch is only lightly tested (MSVC++ 12.0, 32-bit, on Win7 x64, filenames with ASCII characters only). I'm not sure what the motivations for changing to the GetFileAttributesExW() API in filesystem V3 were, so I'm not sure if there's a fundamental flaw in using _wstat() that would prevent using it in V3.

Attachments (1)

is_empty.symlink.diff (1.1 KB ) - added by michael.burr@… 9 years ago.
Possible fix for is_empty() symlink support

Download all attachments as: .zip

Change History (2)

by michael.burr@…, 9 years ago

Attachment: is_empty.symlink.diff added

Possible fix for is_empty() symlink support

comment:1 by Beman Dawes, 7 years ago

Status: newassigned

Also see #9816

Note: See TracTickets for help on using tickets.