Skip to content

Commit 5e70c18

Browse files
committed
goget cleanup fix
1 parent 7f80650 commit 5e70c18

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

abx_pkg/binprovider_goget.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
__package__ = "abx_pkg"
33

44
import os
5+
import shutil
56

67
from pathlib import Path
78

@@ -169,11 +170,25 @@ def default_uninstall_handler(
169170
min_version: SemVer | None = None,
170171
timeout: int | None = None,
171172
) -> bool:
172-
abspath = self.get_abspath(bin_name, quiet=True, no_cache=True)
173-
if not abspath:
174-
return True
173+
install_args = list(install_args or self.get_install_args(bin_name))
174+
install_target = install_args[0] if install_args else bin_name
175+
candidate_name = (
176+
Path(str(install_target).split("@", 1)[0].rstrip("/")).name or bin_name
177+
)
178+
179+
bin_dir = self.bin_dir
180+
assert bin_dir is not None
181+
paths_to_remove: list[Path] = []
182+
requested_path = bin_dir / bin_name
183+
paths_to_remove.append(requested_path)
184+
if candidate_name != bin_name:
185+
paths_to_remove.append(bin_dir / candidate_name)
175186

176-
Path(abspath).unlink(missing_ok=True)
187+
for path in paths_to_remove:
188+
if path.is_dir():
189+
shutil.rmtree(path, ignore_errors=True)
190+
else:
191+
path.unlink(missing_ok=True)
177192
return True
178193

179194
def default_abspath_handler(

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def assert_shallow_binary_loaded(
140140
expected_abspath = provider.bin_dir / loaded.name
141141
assert expected_abspath.exists()
142142
assert expected_abspath == loaded.loaded_abspath
143-
assert expected_abspath.parent == provider.bin_dir
143+
assert expected_abspath.is_relative_to(provider.bin_dir)
144144

145145
if expected_version is not None:
146146
assert loaded.loaded_version >= expected_version

0 commit comments

Comments
 (0)