Skip to content

Commit

Permalink
uninstall: fix uninstalling with if no symlink in bin_dir
Browse files Browse the repository at this point in the history
tt uninstall does not work if there is no symbolic link in bin_dir,
so a check for the presence of a symbolic link has been added.

Closes: [900](tarantool#900)
  • Loading branch information
Japsty committed Nov 1, 2024
1 parent 1cb65d9 commit e5f0c84
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
31 changes: 21 additions & 10 deletions cli/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,30 @@ func remove(program string, programVersion string, directory string,
} else if err != nil {
return false, fmt.Errorf("there was some problem locating %s", path)
}
// Get path where symlink point.
resolvedPath, err := util.ResolveSymlink(linkPath)
if err != nil {
return false, fmt.Errorf("failed to resolve symlink %s: %s", linkPath, err)
}

var isSymlinkRemoved bool
// Remove symlink if it points to program.
if strings.Contains(resolvedPath, fileName) {
err = os.Remove(linkPath)

_, err = os.Lstat(linkPath)
if err != nil {
if !os.IsNotExist(err) {
return false, fmt.Errorf("failed to access %s: %s", linkPath, err)
}
isSymlinkRemoved = false
} else {
// Get path where symlink point.
resolvedPath, err := util.ResolveSymlink(linkPath)
if err != nil {
return false, err
return false, fmt.Errorf("failed to resolve symlink %s: %s", linkPath, err)
}

// Remove symlink if it points to program.
if strings.Contains(resolvedPath, fileName) {
err = os.Remove(linkPath)
if err != nil {
return false, err
}
isSymlinkRemoved = true
}
isSymlinkRemoved = true
}
err = os.RemoveAll(path)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions test/integration/uninstall/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,20 @@ def test_uninstall_tt_missing_version_character(
assert os.path.isfile(os.path.join(tmp_path, "tt_" +
"v" if "v" not in version_to_uninstall else "" +
version_to_uninstall)) is False


def test_uninstall_tt_missing_symlink(tt_cmd, tmp_path):
configPath = os.path.join(tmp_path, config_name)
# Create test config.
with open(configPath, 'w') as f:
f.write(f'env:\n bin_dir: {tmp_path}\n inc_dir:\n')

shutil.copy(tt_cmd, os.path.join(tmp_path, "tt_94ba971"))

uninstall_cmd = [tt_cmd, "uninstall", "tt", "94ba971"]
uninstall_rc, uninstall_output = run_command_and_get_output(uninstall_cmd, cwd=tmp_path)

assert uninstall_rc == 0
assert "tt=94ba971 is uninstalled." in uninstall_output

assert os.path.exists(os.path.join(tmp_path, "tt_" + "94ba971") is False)
Empty file.

0 comments on commit e5f0c84

Please sign in to comment.