Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninstall: fix uninstalling if no symlink in bin_dir #997

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions cli/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,29 @@ 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 %q: %s", linkPath, err)
}
isSymlinkRemoved = false
psergee marked this conversation as resolved.
Show resolved Hide resolved
} 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 %q: %s", linkPath, err)
}

// Remove symlink if it points to program.
if strings.Contains(resolvedPath, fileName) {
if err = os.Remove(linkPath); err != nil {
return false, err
}
isSymlinkRemoved = true
}
isSymlinkRemoved = true
}
err = os.RemoveAll(path)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions test/integration/uninstall/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,23 @@ 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"))

symlink_path = os.path.join(tmp_path, 'tt')
assert not os.path.exists(symlink_path)

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.
Loading