[Boost-bugs] [Boost C++ Libraries] #10731: make_permissions is case-inconsistent and requires unnecessary conversions

Subject: [Boost-bugs] [Boost C++ Libraries] #10731: make_permissions is case-inconsistent and requires unnecessary conversions
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-10-31 23:02:48

#10731: make_permissions is case-inconsistent and requires unnecessary conversions
 Reporter: daniel.kruegler@… | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.56.0 | Severity: Problem
 Keywords: |
 There exist two notable issues with the internal function make_permissions
 in operations.cpp (Windows only):

 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.

 b) The code uses up to four code-conversions (wchar_t->char) to invoke the
 comparison function, all of the following form:

 BOOST_FILESYSTEM_STRICMP(p.extension().string().c_str(), ".exe")

 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

 #include "boost/algorithm/string/predicate.hpp"

 and removal of the BOOST_FILESYSTEM_STRICMP macro definition (which is no-
 where else used):

   perms make_permissions(const path& p, DWORD attr)
     perms prms = fs::owner_read | fs::group_read | fs::others_read;
     if ((attr & 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;

 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.

Ticket URL: <https://svn.boost.org/trac/boost/ticket/10731>
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:17 UTC