Skip to content

Commit

Permalink
Give binary files same error prtin treatment as config files (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom authored Nov 3, 2020
1 parent 00f9a05 commit fd6196d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 54 deletions.
27 changes: 9 additions & 18 deletions cmd/dcrinstall/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func preconditionsBitcoinInstall() error {
currentlyInstalled := 0
expectedInstalled := 0
currentVersion := make(map[string][]string)
var installedBins, notInstalledBins []string
for k := range bitcoinf {
name := bitcoinf[k].Name
filename := filepath.Join(destination, name)
Expand All @@ -169,6 +170,7 @@ func preconditionsBitcoinInstall() error {
version, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Currently not installed: %v", name)
notInstalledBins = append(notInstalledBins, filename)
continue
}
v, err := extractSemVer(string(version))
Expand All @@ -180,27 +182,16 @@ func preconditionsBitcoinInstall() error {
log.Printf("Version installed %v: %v", name, ver)
currentlyInstalled++
currentVersion[ver] = append(currentVersion[ver], name)
installedBins = append(installedBins, filename)
}

// XXX this is commented out because we mix versions.
// Reject mixed versions
//if len(currentVersion) > 1 {
// return fmt.Errorf("Multiple versions of binaries found; " +
// "upgrade requires human intervention")
//}

// If the current version is already installed error out.
//for k := range currentVersion {
// log.Printf("k %v", k)
// // XXX check manifest version against currentVersion
// panic("fixme")
//}

// Determine if everything or nothing is installed
if currentlyInstalled != 0 && currentlyInstalled != expectedInstalled {
return fmt.Errorf("Currently installed binaries does not " +
"match expected installed binaries; upgrade requires " +
"human intervention")
return fmt.Errorf("dcrinstall requires all or none of the "+
"binary files to be installed. This is "+
"to prevent improper installations or upgrades. This "+
"upgrade/install requires human intervention.\n\n%v",
printConfigError(installedBins, notInstalledBins))
}

// Install config files if applicable
Expand Down Expand Up @@ -229,7 +220,7 @@ func preconditionsBitcoinInstall() error {

if currentConfigFiles != 0 && currentConfigFiles != expectedConfigFiles {
return fmt.Errorf("dcrinstall requires all or none of the "+
"configuration files files to be installed. This is "+
"configuration files to be installed. This is "+
"to prevent improper installations or upgrades. This "+
"upgrade/install requires human intervention.\n\n%v",
printConfigError(installedConfigs, notInstalledConfigs))
Expand Down
27 changes: 9 additions & 18 deletions cmd/dcrinstall/dcrdex.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func preconditionsDcrdexInstall() error {
currentlyInstalled := 0
expectedInstalled := 0
currentVersion := make(map[string][]string)
var installedBins, notInstalledBins []string
for k := range dexf {
filename := filepath.Join(destination, dexf[k].Name)

Expand All @@ -109,6 +110,7 @@ func preconditionsDcrdexInstall() error {
version, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Currently not installed: %v", dexf[k].Name)
notInstalledBins = append(notInstalledBins, filename)
continue
}
v, err := extractSemVer(string(version))
Expand All @@ -120,27 +122,16 @@ func preconditionsDcrdexInstall() error {
log.Printf("Version installed %v: %v", dexf[k].Name, ver)
currentlyInstalled++
currentVersion[ver] = append(currentVersion[ver], dexf[k].Name)
installedBins = append(installedBins, filename)
}

// XXX this is commented out because we mix versions.
// Reject mixed versions
//if len(currentVersion) > 1 {
// return fmt.Errorf("Multiple versions of binaries found; " +
// "upgrade requires human intervention")
//}

// If the current version is already installed error out.
//for k := range currentVersion {
// log.Printf("k %v", k)
// // XXX check manifest version against currentVersion
// panic("fixme")
//}

// Determine if everything or nothing is installed
if currentlyInstalled != 0 && currentlyInstalled != expectedInstalled {
return fmt.Errorf("Currently installed binaries does not " +
"match expected installed binaries; upgrade requires " +
"human intervention")
return fmt.Errorf("dcrinstall requires all or none of the "+
"binary files to be installed. This is "+
"to prevent improper installations or upgrades. This "+
"upgrade/install requires human intervention.\n\n%v",
printConfigError(installedBins, notInstalledBins))
}

// Install config files if applicable
Expand Down Expand Up @@ -168,7 +159,7 @@ func preconditionsDcrdexInstall() error {

if currentConfigFiles != 0 && currentConfigFiles != expectedConfigFiles {
return fmt.Errorf("dcrinstall requires all or none of the "+
"configuration files files to be installed. This is "+
"configuration files to be installed. This is "+
"to prevent improper installations or upgrades. This "+
"upgrade/install requires human intervention.\n\n%v",
printConfigError(installedConfigs, notInstalledConfigs))
Expand Down
27 changes: 9 additions & 18 deletions cmd/dcrinstall/decred.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func preconditionsDecredInstall() error {
currentlyInstalled := 0
expectedInstalled := 0
currentVersion := make(map[string][]string)
var installedBins, notInstalledBins []string
for k := range df {
filename := filepath.Join(destination, df[k].Name)

Expand All @@ -244,6 +245,7 @@ func preconditionsDecredInstall() error {
version, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Currently not installed: %v", df[k].Name)
notInstalledBins = append(notInstalledBins, filename)
continue
}
v, err := extractSemVer(string(version))
Expand All @@ -255,27 +257,16 @@ func preconditionsDecredInstall() error {
log.Printf("Version installed %v: %v", df[k].Name, ver)
currentlyInstalled++
currentVersion[ver] = append(currentVersion[ver], df[k].Name)
installedBins = append(installedBins, filename)
}

// XXX this is commented out because we mix versions.
// Reject mixed versions
//if len(currentVersion) > 1 {
// return fmt.Errorf("Multiple versions of binaries found; " +
// "upgrade requires human intervention")
//}

// If the current version is already installed error out.
//for k := range currentVersion {
// log.Printf("k %v", k)
// // XXX check manifest version against currentVersion
// panic("fixme")
//}

// Determine if everything or nothing is installed
if currentlyInstalled != 0 && currentlyInstalled != expectedInstalled {
return fmt.Errorf("Currently installed binaries does not " +
"match expected installed binaries; upgrade requires " +
"human intervention")
return fmt.Errorf("dcrinstall requires all or none of the "+
"binary files to be installed. This is "+
"to prevent improper installations or upgrades. This "+
"upgrade/install requires human intervention.\n\n%v",
printConfigError(installedBins, notInstalledBins))
}

// Install config files if applicable
Expand Down Expand Up @@ -303,7 +294,7 @@ func preconditionsDecredInstall() error {

if currentConfigFiles != 0 && currentConfigFiles != expectedConfigFiles {
return fmt.Errorf("dcrinstall requires all or none of the "+
"configuration files files to be installed. This is "+
"configuration files to be installed. This is "+
"to prevent improper installations or upgrades. This "+
"upgrade/install requires human intervention.\n\n%v",
printConfigError(installedConfigs, notInstalledConfigs))
Expand Down

0 comments on commit fd6196d

Please sign in to comment.