mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
fallback to AUR source in case of PermissionError exception
This commit is contained in:
parent
8374590b62
commit
b83bc5a732
@ -58,11 +58,17 @@ class PackageSource(Enum):
|
||||
|
||||
if maybe_url.scheme and maybe_url.scheme not in ("data", "file") and package_like(maybe_path):
|
||||
return PackageSource.Remote
|
||||
if (maybe_path / "PKGBUILD").is_file():
|
||||
return PackageSource.Local
|
||||
if maybe_path.is_dir():
|
||||
return PackageSource.Directory
|
||||
if maybe_path.is_file() and package_like(maybe_path):
|
||||
return PackageSource.Archive
|
||||
try:
|
||||
if (maybe_path / "PKGBUILD").is_file():
|
||||
return PackageSource.Local
|
||||
if maybe_path.is_dir():
|
||||
return PackageSource.Directory
|
||||
if maybe_path.is_file() and package_like(maybe_path):
|
||||
return PackageSource.Archive
|
||||
except PermissionError:
|
||||
# in some cases (e.g. if you run from your home directory with sudo)
|
||||
# it will try to read files to which it has no access.
|
||||
# lets fallback to AUR source in these cases
|
||||
pass
|
||||
|
||||
return PackageSource.AUR
|
||||
|
@ -52,6 +52,14 @@ def test_resolve_aur_not_package_like(mocker: MockerFixture) -> None:
|
||||
assert PackageSource.Auto.resolve("package") == PackageSource.AUR
|
||||
|
||||
|
||||
def test_resolve_aur_no_access(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the AUR package in case if we cannot read in suggested path
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", side_effect=PermissionError())
|
||||
assert PackageSource.Auto.resolve("package") == PackageSource.AUR
|
||||
|
||||
|
||||
def test_resolve_directory(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the directory
|
||||
@ -65,7 +73,7 @@ def test_resolve_local(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must resolve auto type into the local sources
|
||||
"""
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=True)
|
||||
mocker.patch("pathlib.Path.is_file", autospec=True, side_effect=_is_file_mock(True, True))
|
||||
assert PackageSource.Auto.resolve("path") == PackageSource.Local
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user