mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-07-11 20:11:59 +00:00
fix: adtl remote binary error handling
This commit is contained in:
@@ -70,79 +70,48 @@ 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):
|
||||||
"""Download and install remote binary dependencies for a plugin"""
|
rv = False
|
||||||
|
|
||||||
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')
|
||||||
|
|
||||||
logger.debug(f"Checking package.json at {packageJsonPath}")
|
logger.debug(f"Checking package.json at {packageJsonPath}")
|
||||||
|
|
||||||
if not access(packageJsonPath, R_OK):
|
if 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)
|
||||||
except json.JSONDecodeError as e:
|
if "remote_binary" in packageJson and len(packageJson["remote_binary"]) > 0:
|
||||||
raise ValueError(f"Invalid package.json format: {str(e)}")
|
# create bin directory if needed.
|
||||||
|
chmod(pluginBasePath, 777)
|
||||||
if "remote_binary" not in packageJson:
|
if access(pluginBasePath, W_OK):
|
||||||
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}")
|
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):
|
||||||
raise PermissionError(f"Cannot write to bin directory: {pluginBinPath}")
|
chmod(pluginBinPath, 777)
|
||||||
|
|
||||||
# Download each binary
|
rv = True
|
||||||
for binary in binaries:
|
for remoteBinary in packageJson["remote_binary"]:
|
||||||
try:
|
# Required Fields. If any Remote Binary is missing these fail the install.
|
||||||
# Validate required fields
|
binName = remoteBinary["name"]
|
||||||
required = ['name', 'url', 'sha256hash']
|
binURL = remoteBinary["url"]
|
||||||
if not all(k in binary for k in required):
|
binHash = remoteBinary["sha256hash"]
|
||||||
raise ValueError(f"Missing required binary fields: {required}")
|
logger.debug(f"Attempting to download {binName} from {binURL}")
|
||||||
|
if not await download_remote_binary_to_path(binURL, binHash, path.join(pluginBinPath, binName)):
|
||||||
|
rv = False
|
||||||
|
raise Exception(f"Error Downloading Remote Binary {binName}@{binURL} with hash {binHash} to {path.join(pluginBinPath, binName)}")
|
||||||
|
|
||||||
binPath = path.join(pluginBinPath, binary['name'])
|
|
||||||
logger.debug(f"Downloading {binary['name']} from {binary['url']}")
|
|
||||||
|
|
||||||
if not await download_remote_binary_to_path(
|
|
||||||
binary['url'],
|
|
||||||
binary['sha256hash'],
|
|
||||||
binPath
|
|
||||||
):
|
|
||||||
raise RuntimeError(f"Failed to download binary {binary['name']}")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error downloading binary {binary.get('name', 'unknown')}: {str(e)}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Set final permissions
|
|
||||||
chown(self.plugin_path)
|
chown(self.plugin_path)
|
||||||
chmod(pluginBasePath, 0o555)
|
chmod(pluginBasePath, 555)
|
||||||
return True
|
else:
|
||||||
|
rv = True
|
||||||
|
logger.debug(f"No Remote Binaries to Download")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to download remote binaries: {str(e)}")
|
rv = False
|
||||||
return False
|
logger.debug(str(e))
|
||||||
|
|
||||||
|
return rv
|
||||||
|
|
||||||
"""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