Skip to content

[windows] handle drive letters and backslashes in paths - #2280

Merged
dulmarod merged 1 commit into
meta:mainfrom
jeremydubreil:windows-paths
Oct 28, 2026
Merged

dulmarod merged 1 commit into
meta:mainfrom
jeremydubreil:windows-paths

Conversation

@jeremydubreil

@jeremydubreil jeremydubreil commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, infer cannot take paths apart, which makes it loop forever and run out of memory as soon as it normalizes a path such as C:/infer/...:

  • Filename.parts never terminates on a path with a drive letter, as Filename.dirname "C:/" is "C:/" again, nor on a path rooted at a backslash, as Filename.dirname "\\" is "\\" again.
  • Windows system calls such as getcwd answer with \ as separator, and Unix.realpath even answers in the extended-length form \?\C:\dir\file (\?\UNC\server\share\file for a network path). infer builds its paths with ^/ and compares them as strings, so it needs a single form.

This pull request adds four helpers to Utils:

  • of_win32_path brings a Windows path back to the C:/dir/file form;
  • split_drive splits off the drive letter on Windows, so that Filename.parts only sees the rest of the path;
  • path_parts and of_path_parts split and join paths with the drive letter kept in front of the root part, and always join with /, as Filename.dir_sep is a backslash on Windows.

normalize_path_from, flatten_path and filename_to_relative use them, and realpath returns paths in the C:/dir/file form on Windows. In flatten_path, the drive letter of C:/ is kept without the :, which a file name cannot contain.

On Linux and macOS, split_drive returns the path unchanged, so these functions give the same results as before.

@meta-cla meta-cla Bot added the CLA Signed label Oct 27, 2026
@jeremydubreil
jeremydubreil force-pushed the windows-paths branch 3 times, most recently from 4bda4ae to 3a61074 Compare October 27, 2026 11:29
@jeremydubreil
jeremydubreil marked this pull request as ready for review October 27, 2026 11:32
@dulmarod
dulmarod merged commit 7eeffde into meta:main Oct 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants