Skip to content

🍀 Proposal: Support for rollback in case of error in intermediate steps #1173

Description

@aFlyBird0

What Would You Like to Add? Why Is This Needed?

// applyUpgrade use os.Rename replace old version dtm with the latest one
// (1) rename current dtm file name to `dtm-bak`.
// (2) rename `dtm-tmp` to current dtm file name.
// (3) grant new dtm file execute permission.
// (4) remove `dtm-bak` binary file.
// TODO(hxcGit): Support for rollback in case of error in intermediate steps
func applyUpgrade(workDir string) error {
dtmFilePath := filepath.Join(workDir, dtmFileName)
dtmBakFilePath := filepath.Join(workDir, dtmBakFileName)
dtmTmpFilePath := filepath.Join(workDir, dtmTmpFileName)
if err := os.Rename(dtmFilePath, dtmBakFilePath); err != nil {
return err
}
log.Debugf("Dtm upgrade: rename %s to dtm-bak successfully.", dtmFileName)
if err := os.Rename(dtmTmpFilePath, dtmFilePath); err != nil {
return err
}
log.Debugf("Dtm upgrade: rename dtm-tmp to %s successfully.", dtmFileName)
if err := os.Chmod(dtmFilePath, 0755); err != nil {
return err
}
log.Debugf("Dtm upgrade: grant %s execute permission successfully.", dtmFileName)
if err := os.Remove(dtmBakFilePath); err != nil {
return err
}
log.Debug("Dtm upgrade: remove dtm-bak successfully.")
return nil
}

Design

Anything else

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions