Skip to content

resolve() canonicalises twice and its catch is now unreachable for ~ paths #38

Description

@skipbit

src/platform/path.cpp:113 calls expand() and then canonicalises the result:

try {
    const auto expanded = expand();
    if (expanded) {
        return path { std::filesystem::canonical(expanded.value()._path) };
    }
    ...
} catch (const std::filesystem::filesystem_error& e) {
    return std::unexpected(e);
}

For a path beginning with ~, expand() already canonicalises, so canonical() runs a second time on an already-canonical path. It is idempotent, so the result is right, but it costs another round of stat/readlink.

The catch block is also dead for those paths now: since expand() converts its own filesystem_error into std::unexpected, nothing throws out of the try for a ~ path. It still catches for non-~ paths, where expand() returns the path unchanged and line 115 does the only canonicalisation.

Narrowing the try to the canonical() call would make it symmetric with expand(), which covers only the call that can throw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions