Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 3df18ae

Browse files
author
Dongsu Park
committed
fleetctl: fix wrong error value from matchLocalFileAndUnit()
In matchLocalFileAndUnit(), if os.Stat() returns nil and getUnitFromFile() returns non-nil error, then in the end matchLocalFileAndUnit() will return (false, nil). That's not the expected result. It should have returned the second error that came from getUnitFromFile(). To avoid further potential bugs, let's follow the idiomatic coding style: first check err != nil, and fail-fast. This issue was discoverd by running go tools vet.
1 parent 8e70bce commit 3df18ae

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fleetctl/fleetctl.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,18 +833,19 @@ func lazyCreateUnits(cCmd *cobra.Command, args []string) error {
833833
// Returns true if the contents of the file matches the unit one, false
834834
// otherwise; and any error encountered.
835835
func matchLocalFileAndUnit(file string, su *schema.Unit) (bool, error) {
836-
result := false
837836
a := schema.MapSchemaUnitOptionsToUnitFile(su.Options)
838837

839838
_, err := os.Stat(file)
840-
if err == nil {
841-
b, err := getUnitFromFile(file)
842-
if err == nil {
843-
result = unit.MatchUnitFiles(a, b)
844-
}
839+
if err != nil {
840+
return false, err
841+
}
842+
843+
b, err := getUnitFromFile(file)
844+
if err != nil {
845+
return false, err
845846
}
846847

847-
return result, err
848+
return unit.MatchUnitFiles(a, b), nil
848849
}
849850

850851
// isLocalUnitDifferent compares a Unit on the file system with a one

0 commit comments

Comments
 (0)