Skip to content

[Windows] TSCBasic/Path Asserts with long paths > 260 in length #505

Closed
@kcieplak

Description

@kcieplak

2025-05-01T15:00:18.097Z] TSCBasic/Path.swift:969: Assertion failed
[2025-05-01T15:00:18.097Z]
[2025-05-01T15:00:18.097Z] Current stack trace:
[2025-05-01T15:00:18.097Z]

When creating an absolute path by appending a relative path the appending method is used for Windows.

/// Initializes the AbsolutePath by concatenating a relative path to an
/// existing absolute path, and renormalizing if necessary.
public init(_ absPath: AbsolutePath, _ relPath: RelativePath) {
    self.init(absPath._impl.appending(relativePath: relPath._impl))
}

This in turn calls a windows API that will canonicalize the path adding the \?\ prefix for long path support

func appending(relativePath: Self) -> Self {
        var result: PWSTR?
        _ = self.string.withCString(encodedAs: UTF16.self) { root in
            relativePath.string.withCString(encodedAs: UTF16.self) { path in
                PathAllocCombine(root, path, ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue), &result)
            }
        }
        defer { LocalFree(result) }
        return Self(string: String(decodingCString: result!, as: UTF16.self))
    }

The Assert compares the path to the non prefixed path and will fail.

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