[Boost-bugs] [ boost-Patches-1157160 ] patch for boost::filesystem

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Boost-bugs] [ boost-Patches-1157160 ] patch for boost::filesystem

Patches item #1157160, was opened at 2005-03-05 07:23
Message generated for change (Comment added) made by biochimia
You can respond by visiting:

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
>Resolution: Invalid
Priority: 5
Submitted By: Steven Weiss (fotzor)
Assigned to: Beman Dawes (beman_dawes)
Summary: patch for boost::filesystem

Initial Comment:
when you try to get the branch path of this
under windows the branch path should be "c:\\some_dir".
what is returned instead is "c:" which isn't correct.
so here's the fix:

in path_posix_windows.cpp:

  std::string::size_type leaf_pos( const std::string & str,
    std::string::size_type end_pos ) // end_pos is
past-the-end position
  // return 0 if str itself is leaf (or empty)
    if ( end_pos && str[end_pos-1] == '/' ) return
    std::string::size_type pos( str.find_last_of( '/',
end_pos-1 ) );
        if ( pos == std::string::npos ) pos =
str.find_last_of( '\\', end_pos-1 );                 //
    if ( pos == std::string::npos ) pos =
str.find_last_of( ':', end_pos-2 );
#   endif

    return ( pos == std::string::npos // path itself
must be a leaf (or empty)
#     ifdef BOOST_WINDOWS
      || (pos == 1 && (str[0] == '/' || str[0] ==
'\\')) // or share    // ADDED
#     endif
      ) ? 0 // so leaf is entire string
        : pos + 1; // or starts after delimiter

mfg steven


>Comment By: João Abecasis (biochimia)
Date: 2006-02-04 06:18

Logged In: YES

The claim appears to be wrong. The test program below works
with Boost 1.32, the last release at the time of the
original report. Also works with 1.33.1 and the i18n update
in current CVS.

Exploring a bit deeper it seems the OP might be using
no_check for the name check, in which case '\\' is not
necessarily a valid separator character according to the
portable grammar.

The i18n branch fixes the issue even when using no_check.

I'm setting the patch as invalid. I suppose it could be

#include <boost/filesystem/path.hpp>
#include <cassert>

namespace fs = boost::filesystem;

int main()
    fs::path const
        path1("c:\\some_dir\\some_file.txt", fs::native),
        path2("c:\\some_dir", fs::native),
        path3("c:", fs::native);

    assert(path1.branch_path() == path2);
    assert(path1.branch_path() != path3);


Comment By: Steven Weiss (fotzor)
Date: 2005-03-05 08:24

Logged In: YES

i forgot something...
in branch_path() you must also change the condition of the
if to:

if ( end_pos && (m_path[end_pos-1] == '/' ||
m_path[end_pos-1] == '\\')
        && !detail::is_absolute_root( m_path, end_pos ) )

else it doesn't work proper. perhaps there are other
functions depending on leaf_pos() that must be adjusted as well


You can respond by visiting:

This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
Boost-bugs mailing list
[hidden email]
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost