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

Catch PermissionError when testing for dependencies #432

Closed
wants to merge 6 commits into from
Closed
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
6 changes: 6 additions & 0 deletions ofrak_core/ofrak/core/apk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pathlib
import sys
import tempfile
import logging
from subprocess import CalledProcessError
from dataclasses import dataclass

Expand All @@ -21,6 +22,8 @@
from ofrak.core.magic import Magic, MagicMimeIdentifier
from ofrak_type.range import Range

LOGGER = logging.getLogger(__name__)


APKTOOL = ComponentExternalTool("apktool", "https://ibotpeaches.github.io/Apktool/", "-version")
JAVA = ComponentExternalTool(
Expand Down Expand Up @@ -71,6 +74,9 @@ async def is_tool_installed(self) -> bool:
returncode = await proc.wait()
except FileNotFoundError:
return False
except PermissionError:
LOGGER.warning("Encountered PermissionError while searching PATH for java.")
return False

return 0 == returncode

Expand Down
3 changes: 3 additions & 0 deletions ofrak_core/ofrak/core/squashfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ async def is_tool_installed(self) -> bool:
stdout, stderr = await proc.communicate()
except FileNotFoundError:
return False
except PermissionError:
LOGGER.warning("Encountered PermissionError while searching PATH for unsquashfs.")
return False

if 0 != proc.returncode:
return False
Expand Down
6 changes: 6 additions & 0 deletions ofrak_core/ofrak/core/strings_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import tempfile
import logging
from dataclasses import dataclass
from typing import Dict, Optional

Expand All @@ -8,6 +9,8 @@
from ofrak.model.component_model import ComponentConfig, ComponentExternalTool
from ofrak.model.resource_model import ResourceAttributes

LOGGER = logging.getLogger(__name__)


@dataclass
class StringsAnalyzerConfig(ComponentConfig):
Expand Down Expand Up @@ -45,6 +48,9 @@ async def is_tool_installed(self) -> bool:
await proc.wait()
except FileNotFoundError:
return False
except PermissionError:
LOGGER.warning("Encountered PermissionError while searching PATH for strings command.")
return False

return True

Expand Down
7 changes: 7 additions & 0 deletions ofrak_core/ofrak/model/component_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import logging
from collections import defaultdict
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Set, Type, TypeVar
Expand All @@ -11,6 +12,9 @@
CLIENT_COMPONENT_VERSION = -1


LOGGER = logging.getLogger(__name__)


@dataclass
class ComponentConfig:
"""
Expand Down Expand Up @@ -67,6 +71,9 @@ async def is_tool_installed(self) -> bool:
returncode = await proc.wait()
except FileNotFoundError:
return False
except PermissionError:
LOGGER.warning(f"Encountered PermissionError while searching PATH for {self.tool}.")
return False

return 0 == returncode

Expand Down