[xabt] Fix Windows long path directory removal - #12212
Conversation
RemoveDirFixed retries MAX_PATH failures with an extended path. Strip trailing directory separators before adding the extended path prefix because .NET Framework rejects that form with ERROR_INVALID_NAME. Add a direct task unit test that forces the fallback and verifies the normalized retry path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00f5cfa4-7228-427d-8821-2301070d9929
There was a problem hiding this comment.
Pull request overview
This PR fixes a Windows/.NET Framework MSBuild-host failure (XARDF7024) when RemoveDirFixed retries directory deletion using \\?\ long paths: trailing directory separators are now trimmed before applying the long-path prefix, and a unit test validates the normalized retry path.
Changes:
- Trim trailing directory separators before converting to
\\?\long paths on the Windows retry path. - Route deletion through an injectable
DeleteDirectorydelegate to enable deterministic unit testing. - Add a Windows-only unit test that forces the retry path and verifies the long-path retry uses a normalized directory path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs | Normalizes retry paths before long-path prefixing; adds injectable delete hook for tests. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/RemoveDirTests.cs | Adds coverage for trailing-separator long-path retry behavior on Windows. |
Keep retrying an already converted long path without prepending another extended path prefix. Extend the RemoveDirFixed unit test to cover consecutive DirectoryNotFoundException failures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00f5cfa4-7228-427d-8821-2301070d9929
Keep Files.ToLongPath from adding the extended path prefix more than once and cover the helper directly. RemoveDirFixed retains the Directory.Delete-specific trailing separator normalization. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00f5cfa4-7228-427d-8821-2301070d9929
Explain why RemoveDirFixed removes the trailing directory separator before applying the Windows extended path prefix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 00f5cfa4-7228-427d-8821-2301070d9929
|
/review |
|
✅ Android PR Reviewer completed successfully! |
There was a problem hiding this comment.
✅ LGTM
Clean, well-scoped fix for the Windows XARDF7024 / MAX_PATH directory-removal failure.
What the change does (verified against the full sources):
Files.ToLongPath()is now idempotent — it won't add the\\?\prefix twice. TheStartsWith (LongPathPrefix, StringComparison.Ordinal)guard is correct (the prefix contains no alphabetic characters, soOrdinalis appropriate).RemoveDirFixedtrims trailing directory separators before converting to a long path, matching the root cause: .NET Framework rejects\\?\extended paths that end in a separator withERROR_INVALID_NAME.TrimEndcorrectly handles bothDirectorySeparatorCharandAltDirectorySeparatorChar.- The
DeleteDirectoryinternal test seam is a reasonable, minimal way to simulate the failure without needing a real >260-char path.
Test coverage — good:
ToLongPathIsIdempotentcovers the shared helper directly.LongPathWithTrailingDirectorySeparatorexercises consecutiveRemoveDirFixedretries and asserts the trailing separator is stripped and the prefix is applied only once.
Notes:
- CI is still pending (no failures reported yet) — not blocking review.
- One low-priority inline observation about the long-path conversion consuming a retry attempt/delay; pre-existing and harmless at the default of 10 attempts.
Counts — ❌ 0 ·
Generated by Android PR Reviewer for #12212 · 68.1 AIC · ⌖ 18.5 AIC · ⊞ 6.8K
Comment /review to run again
Visual Studio's .NET Framework MSBuild host can report XARDF7024 while deleting generated Java classes whose paths exceed
MAX_PATH. The retry preserved the trailing directory separator from the MSBuild property, producing an extended path that .NET Framework rejects withERROR_INVALID_NAME.Normalize the directory path before retrying and make
Files.ToLongPath()idempotent so repeated failures cannot add the\\?\prefix more than once. Direct unit coverage verifies both the shared helper and consecutiveRemoveDirFixedretries.Fixes #12207