mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-07-11 21:51:57 +00:00
fix: adtl remote binary error handling
This commit is contained in:
@@ -70,44 +70,79 @@ class PluginBrowser:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def _download_remote_binaries_for_plugin_with_name(self, pluginBasePath: str):
|
async def _download_remote_binaries_for_plugin_with_name(self, pluginBasePath: str):
|
||||||
rv = False
|
"""Download and install remote binary dependencies for a plugin"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Validate plugin path
|
||||||
|
if not path.exists(pluginBasePath):
|
||||||
|
raise ValueError(f"Plugin path does not exist: {pluginBasePath}")
|
||||||
|
|
||||||
packageJsonPath = path.join(pluginBasePath, 'package.json')
|
packageJsonPath = path.join(pluginBasePath, 'package.json')
|
||||||
pluginBinPath = path.join(pluginBasePath, 'bin')
|
pluginBinPath = path.join(pluginBasePath, 'bin')
|
||||||
|
|
||||||
if access(packageJsonPath, R_OK):
|
logger.debug(f"Checking package.json at {packageJsonPath}")
|
||||||
|
|
||||||
|
if not access(packageJsonPath, R_OK):
|
||||||
|
raise PermissionError(f"Cannot read package.json at {packageJsonPath}")
|
||||||
|
|
||||||
with open(packageJsonPath, "r", encoding="utf-8") as f:
|
with open(packageJsonPath, "r", encoding="utf-8") as f:
|
||||||
|
try:
|
||||||
packageJson = json.load(f)
|
packageJson = json.load(f)
|
||||||
if "remote_binary" in packageJson and len(packageJson["remote_binary"]) > 0:
|
except json.JSONDecodeError as e:
|
||||||
# create bin directory if needed.
|
raise ValueError(f"Invalid package.json format: {str(e)}")
|
||||||
chmod(pluginBasePath, 777)
|
|
||||||
if access(pluginBasePath, W_OK):
|
if "remote_binary" not in packageJson:
|
||||||
|
logger.debug("No remote binaries specified")
|
||||||
|
return True
|
||||||
|
|
||||||
|
binaries = packageJson["remote_binary"]
|
||||||
|
if not binaries:
|
||||||
|
logger.debug("Empty remote_binary list")
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Create bin directory with proper permissions
|
||||||
|
chmod(pluginBasePath, 0o777)
|
||||||
|
if not access(pluginBasePath, W_OK):
|
||||||
|
raise PermissionError(f"Cannot write to plugin directory: {pluginBasePath}")
|
||||||
|
|
||||||
if not path.exists(pluginBinPath):
|
if not path.exists(pluginBinPath):
|
||||||
|
logger.debug(f"Creating bin directory at {pluginBinPath}")
|
||||||
mkdir(pluginBinPath)
|
mkdir(pluginBinPath)
|
||||||
|
|
||||||
|
chmod(pluginBinPath, 0o777)
|
||||||
if not access(pluginBinPath, W_OK):
|
if not access(pluginBinPath, W_OK):
|
||||||
chmod(pluginBinPath, 777)
|
raise PermissionError(f"Cannot write to bin directory: {pluginBinPath}")
|
||||||
|
|
||||||
rv = True
|
# Download each binary
|
||||||
for remoteBinary in packageJson["remote_binary"]:
|
for binary in binaries:
|
||||||
# Required Fields. If any Remote Binary is missing these fail the install.
|
try:
|
||||||
binName = remoteBinary["name"]
|
# Validate required fields
|
||||||
binURL = remoteBinary["url"]
|
required = ['name', 'url', 'sha256hash']
|
||||||
binHash = remoteBinary["sha256hash"]
|
if not all(k in binary for k in required):
|
||||||
if not await download_remote_binary_to_path(binURL, binHash, path.join(pluginBinPath, binName)):
|
raise ValueError(f"Missing required binary fields: {required}")
|
||||||
rv = False
|
|
||||||
raise Exception(f"Error Downloading Remote Binary {binName}@{binURL} with hash {binHash} to {path.join(pluginBinPath, binName)}")
|
|
||||||
|
|
||||||
chown(self.plugin_path)
|
binPath = path.join(pluginBinPath, binary['name'])
|
||||||
chmod(pluginBasePath, 555)
|
logger.debug(f"Downloading {binary['name']} from {binary['url']}")
|
||||||
else:
|
|
||||||
rv = True
|
if not await download_remote_binary_to_path(
|
||||||
logger.debug(f"No Remote Binaries to Download")
|
binary['url'],
|
||||||
|
binary['sha256hash'],
|
||||||
|
binPath
|
||||||
|
):
|
||||||
|
raise RuntimeError(f"Failed to download binary {binary['name']}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
rv = False
|
logger.error(f"Error downloading binary {binary.get('name', 'unknown')}: {str(e)}")
|
||||||
logger.debug(str(e))
|
return False
|
||||||
|
|
||||||
return rv
|
# Set final permissions
|
||||||
|
chown(self.plugin_path)
|
||||||
|
chmod(pluginBasePath, 0o555)
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to download remote binaries: {str(e)}")
|
||||||
|
return False
|
||||||
|
|
||||||
"""Return the filename (only) for the specified plugin"""
|
"""Return the filename (only) for the specified plugin"""
|
||||||
def find_plugin_folder(self, name: str) -> str | None:
|
def find_plugin_folder(self, name: str) -> str | None:
|
||||||
|
|||||||
Reference in New Issue
Block a user