Updated appending root directory in canonical/weakly_canonical.

Similar to absolute(), canonical/weakly_canonical needed to be updated
to avoid discarding the root name of the path when appending a root
directory during path composition.
This commit is contained in:
Andrey Semashev 2021-11-05 20:43:32 +03:00
parent cc763cb48e
commit 37bfbbb376

View File

@ -1451,8 +1451,7 @@ path canonical(path const& p, path const& base, system::error_code* ec)
// the preferred separator. This is important on Windows, as in some cases, // the preferred separator. This is important on Windows, as in some cases,
// like paths for network shares and cloud storage mount points GetFileAttributesW // like paths for network shares and cloud storage mount points GetFileAttributesW
// will return "file not found" if the path contains forward slashes. // will return "file not found" if the path contains forward slashes.
path::value_type sep[2] = { path::preferred_separator, static_cast< path::value_type >('\0') }; result += path::preferred_separator;
result /= sep;
// We don't need to check for a symlink after adding a separator. // We don't need to check for a symlink after adding a separator.
continue; continue;
} }
@ -3580,8 +3579,7 @@ path weakly_canonical(path const& p, path const& base, system::error_code* ec)
{ {
// Convert generic separator returned by the iterator for the root directory to // Convert generic separator returned by the iterator for the root directory to
// the preferred separator. // the preferred separator.
path::value_type sep[2] = { path::preferred_separator, static_cast< path::value_type >('\0') }; head += path::preferred_separator;
head /= sep;
} }
else else
{ {
@ -3619,8 +3617,7 @@ path weakly_canonical(path const& p, path const& base, system::error_code* ec)
{ {
// Convert generic separator returned by the iterator for the root directory to // Convert generic separator returned by the iterator for the root directory to
// the preferred separator. // the preferred separator.
path::value_type sep[2] = { path::preferred_separator, static_cast< path::value_type >('\0') }; tail += path::preferred_separator;
tail /= sep;
continue; continue;
} }
#endif #endif