Boost C++ Libraries: Ticket #10731: make_permissions is case-inconsistent and requires unnecessary conversions https://svn.boost.org/trac10/ticket/10731 <p> There exist two notable issues with the internal function make_permissions in operations.cpp (Windows only): </p> <p> a) The usage of the macro BOOST_FILESYSTEM_STRICMP implies case-insensitive comparison, but for compilers different from _MSC_VER it actually calls the case-sensitive function std::strcmp. </p> <p> b) The code uses up to four code-conversions (wchar_t-&gt;char) to invoke the comparison function, all of the following form: </p> <pre class="wiki">BOOST_FILESYSTEM_STRICMP(p.extension().string().c_str(), ".exe") </pre><p> It seems that there exist a simple and consistent way to solve these problems: Replace the macro BOOST_FILESYSTEM_STRICMP by boost::algorithm::iequals and do not perform code conversion. Essentially the make_permissions code could be changed to the following form - assuming an additional inclusion of </p> <pre class="wiki">#include "boost/algorithm/string/predicate.hpp" </pre><p> and removal of the BOOST_FILESYSTEM_STRICMP macro definition (which is no-where else used): </p> <pre class="wiki"> perms make_permissions(const path&amp; p, DWORD attr) { perms prms = fs::owner_read | fs::group_read | fs::others_read; if ((attr &amp; FILE_ATTRIBUTE_READONLY) == 0) prms |= fs::owner_write | fs::group_write | fs::others_write; if (boost::algorithm::iequals(p.extension().c_str(), L".exe") || boost::algorithm::iequals(p.extension().c_str(), L".com") || boost::algorithm::iequals(p.extension().c_str(), L".bat") || boost::algorithm::iequals(p.extension().c_str(), L".cmd")) prms |= fs::owner_exe | fs::group_exe | fs::others_exe; return prms; } </pre><p> Given that boost::algorithm::iequals allows to provide a std::locale object as additional argument, one could improve that solution even more by providing the same locale as that from path_locale() within path.cpp. Unfortunately there is no access within operations.cpp to that function (which is within an unnamed namespace), so realizing this second improvement would require a larger surgery. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10731 Trac 1.4.3 verybigbadboy@… Sun, 08 May 2016 19:11:42 GMT <link>https://svn.boost.org/trac10/ticket/10731#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10731#comment:1</guid> <description> <p> Hello, I have extra note about (b) </p> <p> I have issues with iteration of folder with a lot of files with chinese filenames. </p> <p> one of those file has name similar to "123.是打盤子" it break directory iterator increment method :( thank you. </p> </description> <category>Ticket</category> </item> <item> <author>raad@…</author> <pubDate>Mon, 27 Jun 2016 13:50:37 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/10731#comment:2 https://svn.boost.org/trac10/ticket/10731#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">raad@…</span> added </li> </ul> Ticket Daniel Kruegler <daniel.kruegler@…> Fri, 09 Sep 2016 18:32:24 GMT <link>https://svn.boost.org/trac10/ticket/10731#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10731#comment:3</guid> <description> <p> This issue recently became more problematic because of bug ticket <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/6320" title="#6320: Bugs: race condition in boost::filesystem::path leads to crash when used in ... (reopened)">#6320</a>: Boost Filesystem really should try to prevent internally any code conversions, unless explicitly required by the user. Due to multi-threading issues with the code conversions (partly related boost, but unfortunately also related to the Standard library associated with the Visual Studio compiler), we try hard to prevent any code conversion when working with boost filesystem. Alas, this doesn't help us becoming victim of the code conversion issue, because the above mentioned make_permissions function does perform implicit code conversions through the usage of the string() member function of path. </p> </description> <category>Ticket</category> </item> <item> <author>Daniel Kruegler <daniel.kruegler@…></author> <pubDate>Fri, 09 Sep 2016 19:07:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10731#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10731#comment:4</guid> <description> <p> Beman, I'm willing to provide a patch, but given the potential race conditions in regard to locales (see <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/6320" title="#6320: Bugs: race condition in boost::filesystem::path leads to crash when used in ... (reopened)">#6320</a>), I'm now tending to suggest a less ambitious resolution: Instead of using boost::algorithm::iequals, as originally suggested, I now tend to keep the existing BOOST_FILESYSTEM_STRICMP, with the idea to just replace the function it points to: </p> <pre class="wiki">// some distributions of mingw as early as GLIBCXX__ 20110325 have _wcsicmp, but the // offical 4.6.2 release with __GLIBCXX__ 20111026 doesn't. Play it safe for now, and // only use _wcsicmp if _MSC_VER is defined #if defined(_MSC_VER) // || (defined(__GLIBCXX__) &amp;&amp; __GLIBCXX__ &gt;= 20110325) # define BOOST_FILESYSTEM_STRICMP _wcsicmp #else # define BOOST_FILESYSTEM_STRICMP wcscmp #endif </pre><p> Given that we can replace make_permissions as follows: </p> <pre class="wiki"> perms make_permissions(const path&amp; p, DWORD attr) { perms prms = fs::owner_read | fs::group_read | fs::others_read; if ((attr &amp; FILE_ATTRIBUTE_READONLY) == 0) prms |= fs::owner_write | fs::group_write | fs::others_write; if (BOOST_FILESYSTEM_STRICMP(p.extension().c_str(), L".exe") == 0 || BOOST_FILESYSTEM_STRICMP(p.extension().c_str(), L".com") == 0 || BOOST_FILESYSTEM_STRICMP(p.extension().c_str(), L".bat") == 0 || BOOST_FILESYSTEM_STRICMP(p.extension().c_str(), L".cmd") == 0) prms |= fs::owner_exe | fs::group_exe | fs::others_exe; return prms; } </pre><p> How would you feel about that alternative? </p> </description> <category>Ticket</category> </item> <item> <author>Daniel Kruegler <daniel.kruegler@…></author> <pubDate>Sat, 10 Sep 2016 11:59:08 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/10731 https://svn.boost.org/trac10/ticket/10731 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">filesystem_10731.patch</span> </li> </ul> <p> Patch suggestion </p> Ticket Daniel Kruegler <daniel.kruegler@…> Sat, 10 Sep 2016 12:03:35 GMT <link>https://svn.boost.org/trac10/ticket/10731#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10731#comment:5</guid> <description> <p> Please consider the attached patch. In addition to fixing the need of string conversions it considers one complaint pointed out in <a class="new ticket" href="https://svn.boost.org/trac10/ticket/9480" title="#9480: Patches: make_permissions slower then it needs to be (new)">#9480</a> about four calls to evaluate the path extension, which is now replaced by a single call. </p> </description> <category>Ticket</category> </item> <item> <author>daniel.kruegler@…</author> <pubDate>Tue, 14 Mar 2017 20:51:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10731#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10731#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10731#comment:5" title="Comment 5">Daniel Kruegler &lt;daniel.kruegler@…&gt;</a>: </p> <blockquote class="citation"> <p> Please consider the attached patch. In addition to fixing the need of string conversions it considers one complaint pointed out in <a class="new ticket" href="https://svn.boost.org/trac10/ticket/9480" title="#9480: Patches: make_permissions slower then it needs to be (new)">#9480</a> about four calls to evaluate the path extension, which is now replaced by a single call. </p> </blockquote> <p> Based on that patch suggestion I have created a pull request via the github project: </p> <p> <a class="ext-link" href="https://github.com/boostorg/filesystem/pull/41/commits/755766a0536df599ac0280428defad03dac92cfc"><span class="icon">​</span>https://github.com/boostorg/filesystem/pull/41/commits/755766a0536df599ac0280428defad03dac92cfc</a> </p> <p> Please consider this request, it also solves the performance problem described in ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/9480" title="#9480: Patches: make_permissions slower then it needs to be (new)">#9480</a>. </p> </description> <category>Ticket</category> </item> <item> <author>daniel.kruegler@…</author> <pubDate>Sun, 30 Apr 2017 17:21:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10731#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10731#comment:7</guid> <description> <p> This issue should be marked as resolved by accepting the same pull request as ticket <a class="new ticket" href="https://svn.boost.org/trac10/ticket/9480" title="#9480: Patches: make_permissions slower then it needs to be (new)">#9480</a> for Boost version 1.64. </p> </description> <category>Ticket</category> </item> </channel> </rss>