Skip to content

Commit

Permalink
[lint] fixed linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
na4ma4 committed Oct 24, 2023
1 parent 5c9731f commit 30d4f11
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions cmd/traefik-acme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func main() {
_ = rootCmd.Execute()
}

//nolint:nestif // ifElseChain doesn't seem to be idiomatic here.
func writeFile(filename string, data []byte, perm os.FileMode) (bool, error) {
if _, err := os.Stat(filename); os.IsNotExist(err) {
// File does not exist, just write it.
Expand All @@ -82,29 +81,29 @@ func writeFile(filename string, data []byte, perm os.FileMode) (bool, error) {
}

return true, nil
} else {
// File exists
logrus.WithField("filename", filename).Debugf("file found")
}

ld, lerr := os.ReadFile(filename)
if lerr != nil {
return false, fmt.Errorf("unable to read file for compare: %w", lerr)
}
// File exists
logrus.WithField("filename", filename).Debugf("file found")

if i := bytes.Compare(ld, data); i == 0 {
logrus.WithField("filename", filename).Debugf("file unchanged")
ld, lerr := os.ReadFile(filename)
if lerr != nil {
return false, fmt.Errorf("unable to read file for compare: %w", lerr)
}

return false, nil
}
if i := bytes.Compare(ld, data); i == 0 {
logrus.WithField("filename", filename).Debugf("file unchanged")

logrus.WithField("filename", filename).Debugf("file changed, writing")
return false, nil
}

if werr := os.WriteFile(filename, data, perm); werr != nil {
return true, fmt.Errorf("unable to write file: %w", werr)
}
logrus.WithField("filename", filename).Debugf("file changed, writing")

return true, nil
if werr := os.WriteFile(filename, data, perm); werr != nil {
return true, fmt.Errorf("unable to write file: %w", werr)
}

return true, nil
}

//nolint:nestif // mainCommand can stand a little complexity.
Expand Down

0 comments on commit 30d4f11

Please sign in to comment.