mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
Invalidate stale binary paths after lib moves
This commit is contained in:
parent
426e23f33c
commit
24caacdd1d
@ -588,7 +588,19 @@ class Binary(ModelWithHealthStats, ModelWithStateMachine):
|
||||
@property
|
||||
def is_valid(self) -> bool:
|
||||
"""A binary is valid if it has a resolved path and is marked installed."""
|
||||
return bool(self.abspath) and self.status == self.StatusChoices.INSTALLED
|
||||
if not self.abspath or self.status != self.StatusChoices.INSTALLED:
|
||||
return False
|
||||
try:
|
||||
abspath = Path(self.abspath).expanduser().resolve(strict=False)
|
||||
if not abspath.exists():
|
||||
return False
|
||||
if self.binprovider not in {"", "env", "apt", "brew"}:
|
||||
from archivebox.config.common import get_config
|
||||
|
||||
abspath.relative_to(get_config(include_machine=False).LIB_DIR)
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
return True
|
||||
|
||||
@cached_property
|
||||
def binary_info(self) -> dict:
|
||||
|
||||
@ -337,9 +337,9 @@ class TestBinaryModel:
|
||||
"""Binary.is_valid should be True for installed binaries with a resolved path."""
|
||||
binary = Binary.objects.create(
|
||||
machine=self.machine,
|
||||
name="wget",
|
||||
abspath="/usr/bin/wget",
|
||||
version="1.21",
|
||||
name="python",
|
||||
abspath=sys.executable,
|
||||
version=f"{sys.version_info.major}.{sys.version_info.minor}",
|
||||
status=Binary.StatusChoices.INSTALLED,
|
||||
)
|
||||
|
||||
@ -348,21 +348,21 @@ class TestBinaryModel:
|
||||
def test_binary_manager_get_valid_binary(self):
|
||||
"""BinaryManager.get_valid_binary() should find valid binaries."""
|
||||
# Create invalid binary (no abspath)
|
||||
Binary.objects.create(machine=self.machine, name="wget")
|
||||
Binary.objects.create(machine=self.machine, name="python")
|
||||
|
||||
# Create valid binary
|
||||
Binary.objects.create(
|
||||
machine=self.machine,
|
||||
name="wget",
|
||||
abspath="/usr/bin/wget",
|
||||
version="1.21",
|
||||
name="python",
|
||||
abspath=sys.executable,
|
||||
version=f"{sys.version_info.major}.{sys.version_info.minor}",
|
||||
status=Binary.StatusChoices.INSTALLED,
|
||||
)
|
||||
|
||||
result = cast(BinaryManager, Binary.objects).get_valid_binary("wget")
|
||||
result = cast(BinaryManager, Binary.objects).get_valid_binary("python")
|
||||
|
||||
assert result is not None
|
||||
assert result.abspath == "/usr/bin/wget"
|
||||
assert result.abspath == sys.executable
|
||||
|
||||
def test_binary_update_and_requeue(self):
|
||||
"""Binary.update_and_requeue() should update fields and save."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user