Add GetCanonicalForm to the AbsolutePath API#13088
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a GetFullPath() method to the AbsolutePath struct to provide an API that fully replicates Path.GetFullPath behavior, including resolving relative path segments ("." and "..") and normalizing directory separators on Windows. This enables replacing direct Path.GetFullPath calls in task code with a more controlled API.
Changes:
- Added
GetFullPath()method with optimization to avoid allocations when no normalization is needed - Added comprehensive unit tests for both Windows and Unix platforms
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Framework/PathHelpers/AbsolutePath.cs | Implements GetFullPath() with detection logic for relative segments and separator normalization needs |
| src/Framework.UnitTests/AbsolutePath_Tests.cs | Adds test cases for null paths, Windows path normalization, and Unix path normalization |
f1d94ca to
d9b4d89
Compare
JanProvaznik
left a comment
There was a problem hiding this comment.
should this pr also use this new method on the already migrated tasks where needed?
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
let me do it in separate pr for that, i would like to get this in and start using in my draft prs. |
### Context It is quite often that `Path.GetFullPath` is used in the tasks code. For enlightening we would want to replace it with our own API. The candidate was `TaskEnvironment.GetAbsolutePath` for replacing. However, they do not do the same set of actions. `TaskEnvironment.GetAbsolutePath` only absolutizes the path but does not resolve possible "." and ".." in the path or normalize path separators on Windows. For some scenarios this is critical, for some that does not matter. We should provide an option for fully copy `Path.GetFullPath` behavior ### Changes Made - Added `AbsolutePath.GetCanonicalForm()` ### Testing Added unit tests
### Context It is quite often that `Path.GetFullPath` is used in the tasks code. For enlightening we would want to replace it with our own API. The candidate was `TaskEnvironment.GetAbsolutePath` for replacing. However, they do not do the same set of actions. `TaskEnvironment.GetAbsolutePath` only absolutizes the path but does not resolve possible "." and ".." in the path or normalize path separators on Windows. For some scenarios this is critical, for some that does not matter. We should provide an option for fully copy `Path.GetFullPath` behavior ### Changes Made - Added `AbsolutePath.GetCanonicalForm()` ### Testing Added unit tests
Context
It is quite often that
Path.GetFullPathis used in the tasks code. For enlightening we would want to replace it with our own API. The candidate wasTaskEnvironment.GetAbsolutePathfor replacing.However, they do not do the same set of actions.
TaskEnvironment.GetAbsolutePathonly absolutizes the path but does not resolve possible "." and ".." in the path or normalize path separators on Windows.For some scenarios this is critical, for some that does not matter. We should provide an option for fully copy
Path.GetFullPathbehaviorChanges Made
AbsolutePath.GetCanonicalForm()Testing
Added unit tests