Boost C++ Libraries: Ticket #9824: boost::filesystem::is_empty() doesn't work with symlinks on Windows https://svn.boost.org/trac10/ticket/9824 <p> See the original information on this problem in this Stackoverflow question: </p> <blockquote> <p> hxxp://stackoverflow.com/questions/22668337/boostfilesystemis-empty-returns-false-for-symlinks </p> </blockquote> <p> The person who reported that problem/asked the question on Stackoverflow also set up a github project that demonstrates the problem: </p> <blockquote> <p> hxxps://github.com/monsdar/BoostSymLinkError </p> </blockquote> <p> Basically, the <code>filesystem::is_empty()</code> function doesn't follow a symlink, so it will return false even if the target of the symlink has a length greater than 0. </p> <p> The V2 filesystem library worked for this situation. The difference is that V2 used the <code>stat()</code> function in the VC++ library, while the V3 filesystem library uses the Win32 <code>GetFileAttributesExW()</code> API. The latter does not follow symlinks and returns a file size of 0 regardless of the size of the symlink target. </p> <p> Attached is a diff for libs/filesystem/src/operations.cpp which uses the <code>stat()</code> technique very similar to what was used in filesystem V2. A few differences: </p> <ul><li><code>_wstat()</code> is used instead of <code>stat()</code> to accommodate UNICODE filenames </li><li>a bit test using <code>_S_IFDIR</code> is used to determine if the path is a directory instead of <code>S_ISDIR()</code> because the VC++ library doesn't include a <code>S_ISDIR()</code> or <code>_S_ISDIR()</code> macro. </li></ul><p> 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 <code>GetFileAttributesExW()</code> API in filesystem V3 were, so I'm not sure if there's a fundamental flaw in using <code>_wstat()</code> that would prevent using it in V3. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9824 Trac 1.4.3 michael.burr@… Tue, 01 Apr 2014 09:18:17 GMT attachment set https://svn.boost.org/trac10/ticket/9824 https://svn.boost.org/trac10/ticket/9824 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">is_empty.symlink.diff</span> </li> </ul> <p> Possible fix for is_empty() symlink support </p> Ticket Beman Dawes Thu, 10 Sep 2015 13:03:43 GMT status changed https://svn.boost.org/trac10/ticket/9824#comment:1 https://svn.boost.org/trac10/ticket/9824#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Also see <a class="assigned ticket" href="https://svn.boost.org/trac10/ticket/9816" title="#9816: Bugs: boost::filesystem::is_empty does not work for symbolic links on Windows (assigned)">#9816</a> </p> Ticket