Skip to content

Commit

Permalink
Fix broken file extensions in paths (#47)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rdner authored Jun 29, 2022
1 parent c483f2c commit 483330b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func walk(p, ext, license string, headerBytes []byte, exclude []string, dry bool
}

var currentPath = cleanPathPrefixes(
strings.Replace(path, p, "", 1),
strings.TrimLeft(path, p),
[]string{string(os.PathSeparator)},
)

Expand Down

0 comments on commit 483330b

Please sign in to comment.