-
Notifications
You must be signed in to change notification settings - Fork 120
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: reuse existing license if user didn't set any #104
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,17 @@ func (p *Project) createLicenseFile() error { | |
data := map[string]interface{}{ | ||
"copyright": copyrightLine(), | ||
} | ||
licenseFile, err := os.Create(fmt.Sprintf("%s/LICENSE", p.AbsolutePath)) | ||
|
||
licensePath := p.AbsolutePath + "/LICENSE" | ||
|
||
if p.Legal.Name == "None" { | ||
// If user didn't set any license and an existing license file is found, use that. | ||
if _, err := os.Stat(licensePath); err == nil { | ||
return nil | ||
} | ||
} | ||
|
||
licenseFile, err := os.Create(licensePath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using exiting license makes sense, but this check ignores errors from os.Stat(), (other then fs.ErrNotExits). If the file exits and os.Stat failed, something is very wrong and failing is the best option. But I think there is a better way - do we really want to overwrite existing license file if the user specify the license type? This does not feel like a careful way to modify user source tree. So we can ensure that we never overwrite existing license, and handle the special case when the user did not specify the license, in which we will reuse the existing license. Something like: licenseFile, err := os.OpenFile(licensePath, O_CREATE|O_EXCL, 0755)
if err != nil {
if errors.Is(err, fs.ErrExist) && p.Legal.Name == "None" {
// User did not specify the license - use the existing one.
return nil
}
return err
} |
||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nicer, but the rest of the code use the previous style so this create inconsistency.
It would be better to keep the current style for this change, and if changing the way paths are created is needed, do this in the entire file or project.