boostorg / boostorg/filesystem

'relative' broken on Windows for network paths

Open
#347 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
180
Forks
168
PR merge metrics
No merged PRs in 30d

Description

Commit 11beaba9746583d3ab8e1b03ea8b9699a89d2a8f changed the approach for canonical on Windows, which leads to malfunction of the 'relative' function applied to cases, where the first argument is not on the same drive as the second. Previously this returned an empty path and/or an error code, which is no longer the case. Now this leads to non-existent paths like ''..\..\..\C$\temp\somefile" without any indication of an error.

How to reproduce:
On the command line issue the following commands to define network path mappings to two different drives, e.g.
```
net use X: \\localhost\C$\temp
net use B: \\localhost\E$\somedir
touch C:\temp\somefile
mkdir E:\somedir\test
```

The following test program

```
int main() {
boost::filesystem::path abs("X:/somefile");
boost::filesystem::path relToDest("B:/test");
boost::system::error_code ec;

auto relMapped = boost::filesystem::relative("X:/somefile", "B:/test", ec);

std::cout << "relative path: " << relMapped << "\n";
std::cout << "error code: " << ec << "\n";

return 0;
}
```

returns:

```
relative path: "..\..\..\C$\temp\somefile"
error code: system:0
```

The same issue occurs with 'real' network paths, the above example is only to make this reproduceable on a local machine.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.