Skip to content

Commit

Permalink
Implement Uninstall to complement InstallFromCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lipovetsky committed Aug 7, 2018
1 parent cf603de commit 46866b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 15 additions & 2 deletions binary/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ func InstallFromCache(version, installBaseDir, installDir, cacheDir string) (boo
return true, nil
}

// Uninstall removes installed binaries and symlinks
func Uninstall(version, installBaseDir, installDir string) error {
// Remove binaries
if err := util.RemoveFolderRecursive(installDir); err != nil {
return fmt.Errorf("unable to remove install directory: %s", err)
}
// Remove symlinks
if err := deleteSymLinks(installBaseDir); err != nil {
return fmt.Errorf("unable to remove symlinks: %s", err)
}
return nil
}

func createSymLinks(installDir, symLinkDir string) error {
etcdBinaryPath := filepath.Join(installDir, "etcd")
etcdSymLinkPath := filepath.Join(symLinkDir, "etcd")
Expand All @@ -149,8 +162,8 @@ func createSymLinks(installDir, symLinkDir string) error {
return util.CreateSymLink(etcdctlBinaryPath, etcdctlSymLinkPath)
}

// DeleteSymLinks deletes symlinks created for etcd binaires
func DeleteSymLinks(symLinkDir string) error {
// deleteSymLinks deletes symlinks created for etcd binaires
func deleteSymLinks(symLinkDir string) error {
etcdSymLinkPath := filepath.Join(symLinkDir, "etcd")
etcdctlSymLinkPath := filepath.Join(symLinkDir, "etcdctl")
if err := util.RemoveFile(etcdSymLinkPath); err != nil {
Expand Down
8 changes: 2 additions & 6 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ var resetCmd = &cobra.Command{
log.Print(err)
}
// Remove binaries
if err = util.RemoveFolderRecursive(etcdAdmConfig.InstallDir); err != nil {
log.Print(err)
}
// Remove symlinks
if err = binary.DeleteSymLinks(constants.DefaultInstallBaseDir); err != nil {
log.Print(err)
if err := binary.Uninstall(etcdAdmConfig.Version, etcdAdmConfig.InstallBaseDir, etcdAdmConfig.InstallDir); err != nil {
log.Printf("[binaries] Unable to uninstall binaries: %v", err)
}
if err = util.RemoveFile(etcdAdmConfig.EtcdctlShellWrapper); err != nil {
log.Print(err)
Expand Down

0 comments on commit 46866b8

Please sign in to comment.