Skip to content

Ignore symlinks and hidden (dot) files during --recursive. #644

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

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

allevato
Copy link
Member

Note that hidden files will always be honored if they are specified explicitly among the paths on the command line. Symlinks encountered during recursive traversal or passed on the command line will only be followed if the flag --follow-symlinks is passed. This is meant to avoid symlinks being hidden by shell expansions; for example, running swift-format * where the current directory contains a symlink and following that symlink might be surprising to users.

This PR also adds a new test target for code in the swift-format binary in order to test FileIterator without factoring the binary's code out to a separate library target. We should use this in the future to expand coverage of other functionality like the frontends and commands.

Fixes #643.

case .directory:
dirIterator = FileManager.default.enumerator(
at: next,
includingPropertiesForKeys: nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

You could prefetch the fileResourceTypeKey here. I'm not sure how much it'll speed up the iteration, but I think it'll combine the later look-up into whenever the iterator does file IO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately it looks like the whole URL.resourceValues API is busted on Linux. Switched over to FileManager.attributesOfItem, which doesn't have the issue (but also doesn't benefit from pre-fetching).

Note that hidden files will *always* be honored if they are
specified explicitly among the paths on the command line. Symlinks
encountered during recursive traversal *or* passed on the command
line will only be followed if the flag `--follow-symlinks` is
passed. This is meant to avoid symlinks being hidden by shell
expansions; for example, running `swift-format *` where the
current directory contains a symlink and following that symlink
might be surprising to users.

This PR also adds a new test target for code in the `swift-format`
binary in order to test `FileIterator` without factoring the
binary's code out to a separate library target. We should use this
in the future to expand coverage of other functionality like the
frontends and commands.
@allevato allevato merged commit 8707af0 into swiftlang:main Oct 3, 2023
@allevato allevato deleted the no-dot-files branch October 3, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there a configuration to exclude folders from formatting/linting?
2 participants