Skip to content

templating: add resolvePath function for absolute path resolution#2737

Open
SergioChan wants to merge 1 commit intogo-task:mainfrom
SergioChan:fix-2681-resolvepath
Open

templating: add resolvePath function for absolute path resolution#2737
SergioChan wants to merge 1 commit intogo-task:mainfrom
SergioChan:fix-2681-resolvepath

Conversation

@SergioChan
Copy link

Summary

  • add a new resolvePath template function to resolve relative segments into an absolute path
  • make resolvePath resolve symlinks when available, with a safe fallback to the absolute path when symlink resolution is not possible
  • add focused unit tests for path normalization and symlink resolution behavior

Testing

  • Not run in this environment: go test ./internal/templater
  • Reason: the repository requires Go 1.25 toolchain and this runtime cannot download/provision that toolchain (toolchain not available)

Related

"IsSH": IsSH, // Deprecated
"joinPath": filepath.Join,
"relPath": filepath.Rel,
"resolvePath": resolvePath,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is more granular approach better?

absPath: filepath.Abs
evalSymlinks: filepathEvalSymlinks

Copy link
Author

@SergioChan SergioChan Mar 12, 2026

Choose a reason for hiding this comment

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

Great question! I intentionally kept this as a single resolvePath helper because issue #2681 is about resolving template paths to a final usable absolute path, and exposing one focused function keeps the template surface smaller.

Current behavior is effectively:

  1. filepath.Abs(...)
  2. best-effort filepath.EvalSymlinks(...)
  3. fallback to the absolute path if symlink evaluation fails

If you prefer explicit absPath and evalSymlinks helpers instead, I can split this PR that way.

Copy link
Contributor

Choose a reason for hiding this comment

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

The general approach has been to add individual functions. I think its more useful.

@trulede trulede added the area: templating Changes related to the templating engine. label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: templating Changes related to the templating engine.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a resolvePath or absPath function

2 participants