Skip to content

Skip unused broken symlinks #1201

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

Conversation

matthijskooijman
Copy link
Collaborator

Please check if the PR fulfills these requirements

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • What kind of change does this PR introduce?
    Bug fix
  • What is the current behavior?
  1. When a sketch file (i.e. .ino, .cpp, etc.) is unreadable, it is silently skipped when loading the sketch.
  2. When a sketch contains a broken symlink, sketch loading fails even when the file would not be otherwise loaded (i.e. not a .ino, .cpp, etc type of file).
  • What is the new behavior?
  1. When a sketch file (i.e. .ino, .cpp, etc.) is unreadable (i.e. no permission or otherwise unreadable), an error is thrown.
  2. When a sketch contains a broken symlink, it is skipped if the file would not be otherwise loaded (i.e. not a .ino, .cpp, etc type of file).
  • Does this PR introduce a breaking change, and is
    titled accordingly?

    Sketches that contain unreadable files that are not actually needed can no longer be compiled (they show an error instead of silently skipping the unreadable file), but I would consider such sketches an unsupported corner case.
  • Other information:
    The trigger for this PR was that I had a symlink in my sketch to the compile_commands.json in the build folder, so my editor would find that file and use it for code completion. However, after a reboot, the symlink would become broken, and arduino-cli compile (even with --only-compilation-database would fail, requiring me to remove the symlink and then recreate it afterwards.

The first commit was not strictly required for this problem, but it seemed like a good idea to not silently ignore unreadable files, and raising this error simplifies the second commit, while still raising an error as before on symlinks that would be loaded.

I've omitted testcases from this PR, since a significant of the code paths to test would result in os.Exit, which I think is not supported directly in the test framework. Are there any strategies in place for handling this already (see this post for some suggestions if not)?

@github-actions github-actions bot closed this Mar 30, 2021
@per1234 per1234 reopened this Mar 30, 2021
@matthijskooijman
Copy link
Collaborator Author

Any chance of merging this? It's a fairly straightforward bugfix :-)

When any sketch file that would normally be compiled is unreadable,
SketchLoad would previously just silently skip it, leading to
potentially unexpected results. It is probably better to just error out
and let the user sort out the problem instead.

Additionally, this prepares for improving the handling of broken
symlinks in the next commit.
Previously, SketchLoad would error out on *any* error during file
enumeration, including broken symlinks (where `os.Stat` returns
`ErrNotExist`), even when that symlink would not be loaded (i.e. no
valid extension) anyway.

Now, `ErrNotExist` errors are ignored and a broken symlink is processed
as normal. This changes the code to assume broken symlinks are not
directories and to use the `path` value instead of the `info.Name()`,
since the latter is not available when the `Stat()` call failed.

If, based on the name of the broken symlink, the file would be skipped,
processing continues as normal. If the file would be loaded, then the
existing `os.Open()` call fails (and since the previous commit, returns
an error like before for all broken symlinks).
@matthijskooijman matthijskooijman force-pushed the skip-unused-broken-symlinks branch from dadb144 to 021b449 Compare April 19, 2021 14:03
@matthijskooijman
Copy link
Collaborator Author

Hm, I just rebased this on top of latest master, and discovered that his fix no longer works entirely as expected due to #1235. That PR added support for .json files, so this means that a broken symlink to compile_commands.json now again triggers an error. This is because this PR ensures that broken symlinks that would not be loaded as a sketch file at all are ignored, but with #1235 compile_commands.json is now a valid sketch file that must be loaded, and thus also reports an error if it is a broken symlink...

I'm not directly sure what a good approach for this is, though. Maybe add an explicit ignore for compile_commands.json (since I don't think it should be listed as a sketch file in any case), and then also apply the changes in the PR?

@matthijskooijman
Copy link
Collaborator Author

Closing in favor of #1438.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project conclusion: duplicate Has already been submitted labels Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: duplicate Has already been submitted topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants