Skip to content

Allow weakly_canonical to be used with Windows long paths #247

@emmenlau

Description

@emmenlau

Currently I'm unable to call weakly_canonical() with a long path on Windows. Long path in this context means the Microsoft Windows extension described at https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation. A path can be prefixed by \\?\ and then can have more than 260 characters (with a number of restrictions).

I could trace the problem of using long paths in weakly_canonical() to the method create_file_handle() in

return ::CreateFileW(p.c_str(), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);

This is called via:

file_status head_status = detail::status_impl(head, &local_ec);

But the call fails for long paths. Since in weakly_canonical(), the handle is only needed for the root item, I could work around this by adding some extra handling to create_file_handle(). My added logic is:

  • If the given path has a long-path prefix but is less than 260 characters long, remove the long path prefix and rely on Windows to do the right thing.

Is that reasonable, and could something like this be added to the library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions