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

fleetctl: inform the user about the '-replace' switch in case the units differ #1560

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions fleetctl/fleetctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func getUnitFileFromTemplate(uni *unit.UnitNameInfo, fileName string) (*unit.Uni
}

if tmpl != nil {
isLocalUnitDifferent(fileName, tmpl, true, false)
isLocalUnitDifferent(fileName, tmpl, false)
uf = schema.MapSchemaUnitOptionsToUnitFile(tmpl.Options)
log.Debugf("Template Unit(%s) found in registry", uni.Template)
} else {
Expand Down Expand Up @@ -735,7 +735,7 @@ func checkUnitCreation(arg string) (int, error) {

// if sharedFlags.Replace is not set then we warn in case
// the units differ
different, err := isLocalUnitDifferent(arg, unit, !sharedFlags.Replace, false)
different, err := isLocalUnitDifferent(arg, unit, false)

// if sharedFlags.Replace is set then we fail for errors
if sharedFlags.Replace {
Expand Down Expand Up @@ -838,17 +838,17 @@ func matchLocalFileAndUnit(file string, su *schema.Unit) (bool, error) {
// fatal was not set, it will check again if that file name is an
// instance of a template, if so it will load the template Unit and
// compare it with the provided Unit.
// It takes four arguments; a path to the local Unit on the file system,
// the Unit in the registry, a boolean to warn in case the Units differ;
// and a last boolean to fail in case fatal errors happen.
// It takes three arguments; a path to the local Unit on the file system,
// the Unit in the registry, and a last boolean to fail in case fatal errors
// happen.
// Returns true if the local Unit on file system is different from the
// one provided, false otherwise; and any error encountered.
func isLocalUnitDifferent(file string, su *schema.Unit, warnIfDifferent bool, fatal bool) (bool, error) {
func isLocalUnitDifferent(file string, su *schema.Unit, fatal bool) (bool, error) {
result, err := matchLocalFileAndUnit(file, su)
if err == nil {
// Warn in case unit differs from local file
if result == false && warnIfDifferent {
stderr("WARNING: Unit %s in registry differs from local unit file %s", su.Name, file)
if result == false && !sharedFlags.Replace {
stderr("WARNING: Unit %s in registry differs from local unit file %s. Add --replace to override.", su.Name, file)
}
return !result, nil
} else if fatal {
Expand All @@ -866,8 +866,8 @@ func isLocalUnitDifferent(file string, su *schema.Unit, warnIfDifferent bool, fa
result, err = matchLocalFileAndUnit(templFile, su)
if err == nil {
// Warn in case unit differs from local template unit file
if result == false && warnIfDifferent {
stderr("WARNING: Unit %s in registry differs from local template unit file %s", su.Name, info.Template)
if result == false && !sharedFlags.Replace {
stderr("WARNING: Unit %s in registry differs from local template unit file %s. Add --replace to override.", su.Name, file)
}
return !result, nil
}
Expand Down