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

Fix broken file extensions in paths #47

Merged
merged 1 commit into from
Jun 29, 2022
Merged

Conversation

rdner
Copy link
Member

@rdner rdner commented Jun 28, 2022

Before this change when running go-licenser with the -exclude flag
pointing to a file, the exclusion rule would never work. When walking the
directory currentPath was always losing the first . which
corrupted file extensions.

For example,

./go-licenser -exclude "pkg/proto/messages/struct.pb.go" -license
"Elastic" -ext ".go"

was always replacing the license header in
pkg/proto/messages/struct.pb.go because while walking the
currentPath would become pkg/proto/messages/structpb.go.

After this change currentPath is trimmed from the start only.

Before this change when running go-licenser with the `-exclude` flag
pointing to a file, the exclusion rule would never work. When walking the
directory `currentPath` was always losing the first `.` which
corrupted file extensions.

For example,

```
./go-licenser -exclude "pkg/proto/messages/struct.pb.go" -license
"Elastic" -ext ".go"
```
was always replacing the license header in
`pkg/proto/messages/struct.pb.go` because while walking the
`currentPath` would become `pkg/proto/messages/structpb.go`.

After this change `currentPath` is trimmed from the start only.
@rdner rdner added the bug Something isn't working label Jun 28, 2022
@rdner rdner self-assigned this Jun 28, 2022
@rdner rdner requested a review from a team as a code owner June 28, 2022 18:39
@rdner rdner requested review from zenitraM and shawni and removed request for a team June 28, 2022 18:39
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-06-28T18:39:26.333+0000

  • Duration: 4 min 24 sec

Copy link
Member

@zenitraM zenitraM left a comment

Choose a reason for hiding this comment

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

LGTM so now it only replaces the string at the beginning and not everywhere.

Not sure of the entire logic around this code but won't this be an issue when specifying paths like ./foo gets replaced to /foo? or when a file is hidden like .test.go? -- this was also happening on the old logic, though, so this doesn't really make it worse.

Maybe a further fix could be to make ./ the default path instead of just .

@rdner
Copy link
Member Author

rdner commented Jun 29, 2022

@zenitraM I ran go-licenser without specifying a path, so I assume it used the default one defined in the constant. After this fix I didn't have any issues but I might have missed some edge cases, indeed. Let's keep it like this for now. If I (or someone else) find another issue we can fix it separately. At least there should be no regression.

@rdner rdner merged commit 483330b into elastic:main Jun 29, 2022
@rdner rdner deleted the fix-exclude-files branch June 29, 2022 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants