Skip to content

Skip System.Formats.Tar hard-link tests on platforms that can't create hard links (Android)#126316

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-permission-denied-android
Open

Skip System.Formats.Tar hard-link tests on platforms that can't create hard links (Android)#126316
Copilot wants to merge 2 commits intomainfrom
copilot/fix-permission-denied-android

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Android's SELinux app sandbox denies link syscalls from untrusted apps, causing UnauthorizedAccessException in any test that calls File.CreateHardLink. This produced 154 CI failures across all Android architectures (x86/arm/arm64/x64) on both Mono and CoreCLR.

Description

All test methods in System.Formats.Tar.Tests that call File.CreateHardLink — either directly or via the shared CreateSourceDirectoryForCreateFromDirectory_UsesWriterOptions() helper — are now gated with [ConditionalFact/ConditionalTheory(typeof(MountHelper), nameof(MountHelper.CanCreateHardLinks))]. This is the same pattern already used in the same files for symbolic-link tests.

Changed tests:

  • TarWriter_WriteEntry_File_Tests.WriteEntry_HardLinks
  • TarFile_ExtractToDirectory_File_Tests.HardLinkExtractionRoundtrip
  • TarFile_ExtractToDirectory_File_Tests.HardLinkExtraction_CopyContents
  • TarFile_ExtractToDirectoryAsync_File_Tests.HardLinkExtraction_CopyContentsAsync
  • TarFile_CreateFromDirectory_{File,Stream}_Tests.CreateFromDirectory_UsesWriterOptions
  • TarFile_CreateFromDirectoryAsync_{File,Stream}_Tests.CreateFromDirectoryAsync_UsesWriterOptions

Note: the guard is required even for TarHardLinkMode.CopyContents / preserveLinks=false variants — those tests still invoke File.CreateHardLink during setup to create the source fixture.

MountHelper.CanCreateHardLinks does a live capability probe (Lazy<bool>), so tests are skipped correctly on any platform that disallows hard links, not just Android.

…ks guards

Android's SELinux app sandbox prohibits hard link creation (denied { link }).
Tests that call File.CreateHardLink fail with UnauthorizedAccessException.
Guard all affected tests with [ConditionalFact/ConditionalTheory(typeof(MountHelper),
nameof(MountHelper.CanCreateHardLinks))] to skip them when hard links are unavailable.

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/9ff99a47-c680-4c34-9df0-eb63eaf86bdd

Co-authored-by: rzikm <32671551+rzikm@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix UnauthorizedAccessException for creating hard links in Android app Skip System.Formats.Tar hard-link tests on platforms that can't create hard links (Android) Mar 30, 2026
Copilot AI requested a review from rzikm March 30, 2026 14:11
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-formats-tar
See info in area-owners.md if you want to be subscribed.

@rzikm
Copy link
Copy Markdown
Member

rzikm commented Mar 31, 2026

/azp list

@azure-pipelines
Copy link
Copy Markdown

CI/CD Pipelines for this repository:

@rzikm
Copy link
Copy Markdown
Member

rzikm commented Mar 31, 2026

/azp run runtime-extra-platforms

@rzikm rzikm requested a review from a team March 31, 2026 09:04
@rzikm rzikm marked this pull request as ready for review March 31, 2026 09:04
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copilot AI review requested due to automatic review settings March 31, 2026 09:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates System.Formats.Tar link-related tests to skip hard-link scenarios on platforms where creating hard links is not permitted (notably Android, where SELinux denies link syscalls in the app sandbox), preventing widespread CI failures.

Changes:

  • Gate all tests that create hard links (directly or via shared helpers) with MountHelper.CanCreateHardLinks.
  • Align hard-link test gating with the existing symbolic-link test pattern already used in the same test areas.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.File.Tests.cs Converts the hard-link writer test to ConditionalTheory guarded by MountHelper.CanCreateHardLinks.
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectory.File.Tests.cs Guards hard-link extraction tests (ConditionalTheory/ConditionalFact) using MountHelper.CanCreateHardLinks.
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectoryAsync.File.Tests.cs Guards async hard-link extraction test with ConditionalFact using MountHelper.CanCreateHardLinks.
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectory.File.Tests.cs Guards CreateFromDirectory_UsesWriterOptions (which uses a hard-link fixture) with ConditionalTheory.
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectory.Stream.Tests.cs Guards CreateFromDirectory_UsesWriterOptions stream variant with ConditionalTheory.
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectoryAsync.File.Tests.cs Guards async file variant CreateFromDirectoryAsync_UsesWriterOptions with ConditionalTheory.
src/libraries/System.Formats.Tar/tests/TarFile/TarFile.CreateFromDirectoryAsync.Stream.Tests.cs Guards async stream variant CreateFromDirectoryAsync_UsesWriterOptions with ConditionalTheory.

@rzikm rzikm requested a review from a team March 31, 2026 09:12
Copy link
Copy Markdown
Member

@alinpahontu2912 alinpahontu2912 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

UnauthorizedAccessException: Permission denied creating hard links in Android app sandbox

4 participants