Skip to content

Commit

Permalink
[PLAT-15943] Yba Installer symlinking to be idempotent
Browse files Browse the repository at this point in the history
Summary:
We found that the symlink function in yba-installer does not handle
the case where the symlink was already created. A new symlink in this
scenario leads to a file system loop.

We now detect when the symlink already exists, and delete and recreate it
if it does.

If the target file exists and is not a symlink, we should fail, as this
is an unexpected scenario

Test Plan: tested new symlink function during migration`

Reviewers: muthu, sanketh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D39748
  • Loading branch information
shubin-yb committed Nov 11, 2024
1 parent 601e28a commit bdd128d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions managed/yba-installer/pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ func CreateSymlink(pkgDir string, linkDir string, binary string) error {

// Symlink implements a more generic symlink utility.
func Symlink(src string, dest string) error {
if stat, err := os.Lstat(dest); err == nil {
if stat.Mode()&os.ModeSymlink == 0 {
return fmt.Errorf("destination symlink '%s' already exists and is not a symlink", dest)
}
log.Debug("Deleting existing symlink at " + dest)
if err := os.Remove(dest); err != nil {
return fmt.Errorf("failed to delete symlink '%s': %w", dest, err)
}
}
out := shell.Run("ln", "-sf", src, dest)
out.SucceededOrLog()
return out.Error
Expand Down

0 comments on commit bdd128d

Please sign in to comment.