Skip to content

[xabt] Fix Windows long path directory removal - #12212

Merged
jonathanpeppers merged 5 commits into
mainfrom
jonathanpeppers-investigate-xardf7024
Jul 24, 2026
Merged

[xabt] Fix Windows long path directory removal#12212
jonathanpeppers merged 5 commits into
mainfrom
jonathanpeppers-investigate-xardf7024

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Jul 23, 2026

Copy link
Copy Markdown
Member

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 with ERROR_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 consecutive RemoveDirFixed retries.

Fixes #12207

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

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
Copilot AI review requested due to automatic review settings July 23, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DeleteDirectory delegate 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.

Comment thread src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs
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
@jonathanpeppers jonathanpeppers changed the title [xabt] Fix long path directory removal [xabt] Fix Windows long path directory removal Jul 23, 2026
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Jul 23, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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. The StartsWith (LongPathPrefix, StringComparison.Ordinal) guard is correct (the prefix contains no alphabetic characters, so Ordinal is appropriate).
  • RemoveDirFixed trims trailing directory separators before converting to a long path, matching the root cause: .NET Framework rejects \\?\ extended paths that end in a separator with ERROR_INVALID_NAME. TrimEnd correctly handles both DirectorySeparatorChar and AltDirectorySeparatorChar.
  • The DeleteDirectory internal test seam is a reasonable, minimal way to simulate the failure without needing a real >260-char path.

Test coverage — good:

  • ToLongPathIsIdempotent covers the shared helper directly.
  • LongPathWithTrailingDirectorySeparator exercises consecutive RemoveDirFixed retries 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 · ⚠️ 0 · 💡 1. Nice, focused fix with matching regression tests.

Generated by Android PR Reviewer for #12212 · 68.1 AIC · ⌖ 18.5 AIC · ⊞ 6.8K
Comment /review to run again

Comment thread src/Xamarin.Android.Build.Tasks/Tasks/RemoveDirFixed.cs
@jonathanpeppers
jonathanpeppers merged commit e8d8678 into main Jul 24, 2026
44 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-investigate-xardf7024 branch July 24, 2026 13:42
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In VS2026, Pack a android app: XARDF7024 System.IO.IOException: 文件名、目录名或卷标语法不正确。

3 participants