Subject: [Boost-bugs] [Boost C++ Libraries] #9824: boost::filesystem::is_empty() doesn't work with symlinks on Windows
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-04-01 09:17:13
#9824: boost::filesystem::is_empty() doesn't work with symlinks on Windows
------------------------------+------------------------
Reporter: michael.burr@⦠| Owner: bemandawes
Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.56.0 | Severity: Regression
Keywords: |
------------------------------+------------------------
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/9824> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC