Skip to content

🍀 Proposal: Automatically detect binary filenames on dtm upgrade #1110

Closed

Description

@aFlyBird0

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

When I executed dtm upgrade, an error occurred.

image

Because now the name of dtm binary is hard coded to "dtm".

dtmFileName = "dtm"

// applyUpgrade use os.Rename replace old version dtm with the latest one
// (1) rename `dtm` to `dtm-bak`.
// (2) rename `dtm-tmp` to `dtm`.
// (3) grant new `dtm` 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.Debug("Dtm upgrade: rename dtm to dtm-bak successfully.")
if err := os.Rename(dtmTmpFilePath, dtmFilePath); err != nil {
return err
}
log.Debug("Dtm upgrade: rename dtm-tmp to dtm successfully.")
if err := os.Chmod(dtmFilePath, 0755); err != nil {
return err
}
log.Debug("Dtm upgrade: grant dtm execute permission successfully.")
if err := os.Remove(dtmBakFilePath); err != nil {
return err
}
log.Debug("Dtm upgrade: remove dtm-bak successfully.")
return nil
}

If the binary name is not "dtm", such as "dtm-darwin-arm64", it will occur an error.

Design

We should be should to automatically detect binary filenames.

Note: you can use os.Executable() to get the binary path.

Anything else

Don't forget to update related code comments.

Happy coding!

Activity

  1. CrazyCollin commented on Sep 23, 2022

    @CrazyCollin

    Hi,@aFlyBird0, I wanna have a try, plz assign to me.

  2. daniel-hutao commented on Sep 29, 2022

    @daniel-hutao
    Member

    /assign @CrazyCollin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions