Skip to content

Commit b83cf2f

Browse files
committed
fix(plugin-manager): explain why an update failed validation (cause + remediation)
Classify the validation failure in pre_plugin_checks instead of surfacing the raw txz error: distinguish low disk space (reporting actual free space), a download/network failure, and a genuine bad hash. Store a short summary plus a full actionable message in the marker. ShowPlugins.php shows the short cause as a visible second line under the "update validation failed" status and puts the full guidance in the tooltip, so the status answers "why did this fail and what do I do" instead of raising questions. Wording follows existing GUI conventions: lowercase status label like the other plugin statuses (up-to-date, cannot check, not available) and terse messages in the style of "Not enough free space, need at least %s MB". The hook runs without the gettext setup, so its strings are plain (the prior code also echoed untranslated reasons); only ShowPlugins.php uses _().
1 parent b333432 commit b83cf2f

2 files changed

Lines changed: 35 additions & 9 deletions

File tree

emhttp/plugins/dynamix.plugin.manager/include/ShowPlugins.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,19 @@
196196
$info = json_decode(file_get_contents($invalid),true) ?: [];
197197
$newver = (string)($info['version'] ?? '');
198198
if ($newver !== '' && strcmp($newver,$version) > 0) {
199-
$reason = trim((string)($info['reason'] ?? ''));
199+
$summary = trim((string)($info['summary'] ?? $info['reason'] ?? ''));
200+
$message = trim((string)($info['message'] ?? $summary));
200201
$version .= "<br><span class='red-text'>$newver</span>";
201-
$status = "<span class='warning'".($reason ? " title='".htmlspecialchars($reason,ENT_QUOTES)."'" : "")."><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> "._('Update validation failed')."</span>";
202+
$status = "<span class='warning'".($message ? " title='".htmlspecialchars($message,ENT_QUOTES)."'" : "")."><i class='fa fa-exclamation-triangle' aria-hidden='true'></i> "._('update validation failed')."</span>";
203+
if ($summary !== '') $status .= "<br><span class='orange-text' style='font-size:smaller'>".htmlspecialchars($summary,ENT_QUOTES)."</span>";
202204
} else {
203205
@unlink($invalid);
204206
}
205207
}
206208
}
207209
if (strpos($status,'update')!==false) $rank = '0';
208210
elseif (strpos($status,'install')!==false) $rank = '1';
209-
elseif (strpos($status,'Update validation failed')!==false) $rank = '0';
211+
elseif (strpos($status,'update validation failed')!==false) $rank = '0';
210212
elseif ($status=='need check') $rank = '2';
211213
elseif ($status=='up-to-date') $rank = '3';
212214
else $rank = '4';

emhttp/plugins/dynamix.plugin.manager/pre-hooks/pre_plugin_checks

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,36 @@ case 'plugin':
4949
exec("$docroot/plugins/dynamix.plugin.manager/scripts/plugin validate ".escapeshellarg($new_plugin)." 2>&1", $output, $retval);
5050
if ($retval != 0) {
5151
$reason = trim(preg_replace('/^plugin:\s*/m', '', implode("\n", $output)));
52-
echo ($reason ?: 'validation failed')."\n";
53-
// An update is available but failed validation. Record why so the webGUI
54-
// can surface it, instead of silently reverting to "up-to-date". The most
55-
// common cause is the update files not downloading because the root
56-
// filesystem is full.
57-
file_put_contents($invalid, json_encode(['version'=>$new_version, 'reason'=>$reason]));
52+
// Classify the failure so the webGUI can explain it (and what to do)
53+
// instead of silently reverting to "up-to-date". Validation downloads
54+
// the update's files to /tmp (rootfs) and checks their hash, so the
55+
// usual culprits are a full root filesystem, a transient network error,
56+
// or a genuine bad hash.
57+
$free_kb = (int)trim((string)@shell_exec("df -Pk /tmp 2>/dev/null | awk 'NR==2{print \$4}'"));
58+
$free_mb = $free_kb > 0 ? intdiv($free_kb, 1024) : 0;
59+
if (stripos($reason, 'hash') !== false) {
60+
$category = 'integrity';
61+
$summary = 'integrity check failed (bad hash)';
62+
$message = 'The update failed its integrity check (bad hash). The download may be incomplete or corrupt. Check for updates again shortly.';
63+
} elseif ($free_kb > 0 && $free_kb < 102400) {
64+
$category = 'diskspace';
65+
$summary = 'low on disk space';
66+
$message = sprintf('Not enough free space to download and verify the update (%s MB free). Free up space and check for updates again.', $free_mb);
67+
} else {
68+
$category = 'download';
69+
$summary = 'update files could not be downloaded';
70+
$message = 'Could not download the update files to verify them. This may be a temporary network problem. Check for updates again shortly.';
71+
}
72+
echo "$message\n";
73+
// An update is available but failed validation. Record the available
74+
// version and the classified reason so the webGUI can surface it.
75+
file_put_contents($invalid, json_encode([
76+
'version' => $new_version,
77+
'category' => $category,
78+
'summary' => $summary,
79+
'message' => $message,
80+
'reason' => $reason,
81+
]));
5882
// restore original plugin and undo update
5983
copy($plugin, $new_plugin);
6084
} else {

0 commit comments

Comments
 (0)