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

🐛 Don't recurse into hidden directories #1972

Closed
wants to merge 1 commit into from
Closed

🐛 Don't recurse into hidden directories #1972

wants to merge 1 commit into from

Conversation

daenney
Copy link

@daenney daenney commented Jan 24, 2021

checkDir() currently recurses into hidden directories at the root. This
is a problem, because only the directory itself will have a . at the
root of it's path, but any files within it won't when calling info.Name.
This causes init to fail on a directory containing any hidden directory
with files within them, such as .git.

Since we use filepath.Walk(".") we can't skip a directory that just
starts with ., as that would include the current directory. So instead
we also check that Name() doesn't return just "."

Fixes #1971

@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 24, 2021
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jan 24, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @daenney!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubebuilder has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @daenney. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 24, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: daenney
To complete the pull request process, please assign estroz after the PR has been reviewed.
You can assign the PR to them by writing /assign @estroz in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

checkDir() currently recurses into hidden directories at the root. This
is a problem, because only the directory itself will have a . at the
root of it's path, but any files within it won't when calling info.Name.
This causes init to fail on a directory containing any hidden directory
with files within them, such as .git.

Since we use filepath.Walk(".") we can't skip a directory that just
starts with ., as that would include the current directory. So instead
we also check that Name() doesn't return just "."
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jan 24, 2021
@@ -207,6 +207,9 @@ func checkDir() error {
if err != nil {
return err
}
if info.IsDir() && info.Name() != "." && strings.HasPrefix(info.Name(), ".") {
return filepath.SkipDir
}
Copy link
Member

Choose a reason for hiding this comment

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

Will not it allow scaffold projects in a directory that has another directory as well?
Then, note that it goes against the purpose of the check. We would like to not allow it because it means that we cannot ensure that the tool is able to do properly all required scaffolds.

Copy link
Author

@daenney daenney Jan 25, 2021

Choose a reason for hiding this comment

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

I believe the check is too paranoid. it needs to not only exclude files starting with a dot, it needs to not recurse into hidden directories.

It will only allow you to scaffold into directories that have hidden directories at the root. For example, if you try to scaffold right now in a directory that you've just run a git init on, it'll fail. Though .git has a . prefix, the HEAD file in .git/HEAD does not, so it'll fail because info.Name() will return HEAD, not .git/HEAD.

Similarly if you have opened that directory in an editor already and something like a .vscode exists it'll fail to scaffold. None of these directories should have any impact on the ability to scaffold. If we ignore hidden files, we should ignore hidden directories too.

@daenney
Copy link
Author

daenney commented Jan 26, 2021

Closed in favour of #1944

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 26, 2021
@daenney daenney closed this Jan 26, 2021
@daenney daenney deleted the fix-checkdir branch January 26, 2021 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

failed to initialize project with "go.kubebuilder.io/v3"
3 participants