Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: canonicalize load paths in load_from functions #1462

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

Br1ght0ne
Copy link
Member

@Br1ght0ne Br1ght0ne commented Jul 18, 2024

This helps users by showing an accurate, absolute path in error messages.

Checklist

  • I have linked to any relevant issues.
  • I have updated the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary labels.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@Br1ght0ne Br1ght0ne marked this pull request as draft July 18, 2024 14:31
@Br1ght0ne Br1ght0ne mentioned this pull request Jul 19, 2024
4 tasks
Cargo.toml Show resolved Hide resolved
@Br1ght0ne Br1ght0ne marked this pull request as ready for review July 29, 2024 14:21
`absolute` resolves the path against `workdir`, `clean` removes extra `..` inside.
Using `clean` before `absolute` with paths that go outside of the root
(e.g., "/one/two/../../../above_root") can lead to losing levels of `..`
@digorithm
Copy link
Member

Do you mind resolving these conflicts so we can wrap up this PR?

)
})?;
let clean_file_path = path_clean::clean(absolute_file_path);
let code = fs::read(&clean_file_path).map_err(|e| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change this just slightly:

  1. read the code with the original path
  2. if that fails, clean up the path and report that we failed to read the clean path
  3. if cleaning up fails fallback to the original path and report that

Because we don't need a "clean" path to read the data only for diagnostics. So in the eventuality of any schenanigans with symlinks we'll still function, only our reporting might or might not be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-experience enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants