Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexically_relative and lexically_poximate give unexpected result #76

Closed
madebr opened this issue Jun 21, 2018 · 4 comments
Closed

lexically_relative and lexically_poximate give unexpected result #76

madebr opened this issue Jun 21, 2018 · 4 comments

Comments

@madebr
Copy link

@madebr madebr commented Jun 21, 2018

/home/user/documents/file.txt relative to /home/user/. should be documents/file.txt.

c++17 gives the expected result.

#include <filesystem>
#include <iostream>

namespace fs = std::filesystem;

#include <boost/filesystem.hpp>

namespace bfs = boost::filesystem;

int main() {
    std::string hs = "/home/user/.";
    std::string ps = "/home/user/documents/file.txt";

    {
        fs::path h = hs;
        fs::path p = ps;
        std::cout << "relative: " << p.lexically_relative(h) << '\n'
                  << "proximate: " << p.lexically_proximate(h) << '\n';
    }

    {
        bfs::path h = hs;
        bfs::path p = ps;
        std::cout << "relative: " << p.lexically_relative(h) << '\n'
                  << "proximate: " << p.lexically_relative(h) << '\n';
    }

    return 0;
}

outputs

relative: "documents/file.txt"
proximate: "documents/file.txt"
relative: "../documents/file.txt"
proximate: "../documents/file.txt"
@RichardCrewe

This comment has been minimized.

Copy link

@RichardCrewe RichardCrewe commented Aug 14, 2019

I've been using c++14 and have encountered this problem on OSX, but not Linux.

Boost 1.67
Compiler on OSX: Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Compiler on Linux: g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609

@RichardCrewe

This comment has been minimized.

Copy link

@RichardCrewe RichardCrewe commented Aug 14, 2019

The trailing dot in the parent path (hs in the example above) is confusing lexically_relative. In my case I discovered it as the boost::filesystem::temp_directory_path() returns a path with a trailing slash on OSX, but not Linux. This trailing slash is effectively normalised to a trailing slash dot by the path iterator.

@rcdailey

This comment has been minimized.

Copy link

@rcdailey rcdailey commented Oct 4, 2019

I'm seeing this issue in Boost 1.70. Here is my code example:

namespace fs = boost::filesystem;

int main()
{
    fs::path parentPath("/home/user1/");
    fs::path childPath("/home/user1/Downloads/Books");
    std::cout << childPath.lexically_relative(parentPath) << '\n';
}

Live sample is here

The output is "../Downloads/Books" but should actually be "Downloads/Books". When will this get fixed?

EDIT: Looks like boost::filesystem::relative() also has this issue:

std::cout << fs::relative(childPath, parentPath) << '\n';

Outputs: "../Downloads/Books".

@rcdailey

This comment has been minimized.

Copy link

@rcdailey rcdailey commented Oct 5, 2019

@Lastique Thank you for the fix!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.