Improve broken symlink and other error handling #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes a few changes that came up when working on (a replacement PR for) arduino/arduino-cli#1201, but which probably are a good idea by themselves. This PR contains four commits:
Stat()
errors, but instead just add such problematic files to the returned list and let the caller decide whether these files are really needed at all and an error is appropriate. I needed this for broken symlinks (which return DoesNotExist), but it also seemed useful to ignore permission errors, and let the caller decide.Lstat()
method, needed for the next commit.CopyDirTo()
really ignore symlinks, as was seemingly intended based on a comment in the code. I noticed this problem when adding a broken symlink to the testdata (needed to test the next commit), and then discovered that a broken symlink madeCopyDirTo()
fail, and a correct symlink was actually duplicated, potentially leading to a lot more diskspace. Now symlinks are ignored entirely, at least until properly copying them is implemented.FilterOutDirs
incorrectly marking files with stat errors (such as broken symlinks) as directories and filtering them out. I needed this because commit 1. ensures that broken symlinks end up in theReadDirRecursive()
output, but inside arduino-cliFilterOutDirs()
would again throw them away, IMHO inappropriately.Note also arduino/arduino-cli#1353 (comment), which makes an additional suggestion on improving the
ReadDirRecursive
API (adding a callback to control pruning the recursion). If implemented, this might remove the need for commit 1., especially if the callback could also control whether an error is returned on a failed stat call.