Uh oh!
There was an error while loading. Please reload this page.
Fix PathUtils.IsSymlink throwing on common lstat failures - #183
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts PathUtils.IsSymlink to treat common lstat failures (e.g., missing path / access denied) as non-exceptional and return false, improving robustness when walking directory trees. It also introduces NUnit coverage for the updated behavior and attempts to expose internals to the test assembly.
Changes:
- Update
PathUtils.IsSymlinkto returnfalsefor specificerrnovalues instead of throwing. - Add
PathUtilsTeststo validate symlink detection and non-existent-path behavior. - Add an
InternalsVisibleToentry intended to allow tests to access internal types.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| Xamarin.MacDev/Xamarin.MacDev.csproj | Adds InternalsVisibleTo for the tests assembly. |
| Xamarin.MacDev/PathUtils.cs | Updates IsSymlink error handling for lstat failures. |
| tests/PathUtilsTests.cs | Adds new NUnit tests for PathUtils behavior. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
a1ab463 to
172d659CompareIsSymlink previously threw an exception for any lstat failure, including ENOENT (file not found) and EACCES (permission denied). These are expected non-exceptional conditions — especially when walking directory trees to check for symlinks via IsSymlinkOrHasParentSymlink. Now returns false for ENOENT, EACCES, and ENOTDIR, and only throws for genuinely unexpected errno values. Uses named constants for clarity. Also adds InternalsVisibleTo for the test project and new PathUtilsTests (5 tests covering non-existent, regular, symlink, parent-walk, and ENOTDIR). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
172d659 to
ae7c268Compare- Remove unused 'using System;' from PathUtilsTests.cs - Add IsSymlinkOrHasParentSymlink_ReturnsTrue_WhenParentIsSymlink test that creates a symlink directory and verifies parent traversal Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Summary
IsSymlinkpreviously threw for anylstatfailure, including file-not-found and permission-denied. These are expected when walking directory trees (e.g.IsSymlinkOrHasParentSymlink).Now returns
falsefor ENOENT (2), EACCES (13), and ENOTDIR (20), only throwing for genuinely unexpected errors.Testing
Added
PathUtilsTestswith 4 tests verifying behavior for non-existent files, regular files, symlinks, and parent-symlink traversal.Also adds
InternalsVisibleTofor the test assembly.