Skip to content

Commit df5d273

Browse files
Squidly271claude
andcommitted
fix: normalize corrupt Docker info cache before the refresh decision
Addresses CodeRabbit: the is_array guard was only at getAllInfo's return, so a truthy scalar from a corrupt cache made both !$containers and empty() false, skipping the refresh and returning [] indefinitely. Normalize non-arrays to [] right after the read so the existing refresh path rebuilds from Docker. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4ccdd1f commit df5d273

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

  • source/community.applications/usr/local/emhttp/plugins/community.applications/include

source/community.applications/usr/local/emhttp/plugins/community.applications/include/helpers.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,8 +2033,15 @@ function getAllInfo($force=false) {
20332033
global $DockerTemplates, $DockerClient;
20342034

20352035
$containers = readJsonFile(CA_PATHS['info']);
2036+
// Normalize a corrupt cache (readJsonFile can decode a scalar) to [] right
2037+
// here, before the refresh decision. Otherwise a truthy scalar leaves both
2038+
// empty() and the refresh path false, so we would return [] on every
2039+
// non-forced call without ever rebuilding from Docker.
2040+
if ( ! is_array($containers) ) {
2041+
$containers = [];
2042+
}
20362043

2037-
if ( $force || ! $containers || empty($containers) ) {
2044+
if ( $force || empty($containers) ) {
20382045
if ( caIsDockerRunning() ) {
20392046
$info = $DockerTemplates->getAllInfo(false,true,true);
20402047
$containers = $DockerClient->getDockerContainers();
@@ -2050,11 +2057,10 @@ function getAllInfo($force=false) {
20502057
} else {
20512058
debug("Cached info update");
20522059
}
2053-
// Guard so a corrupt CA_PATHS['info'] cache that readJsonFile decodes to a
2054-
// scalar can never reach the typed array $info params downstream (which
2055-
// would TypeError). is_array (not an (array) cast) so a scalar becomes an
2056-
// empty array, not a one-element array wrapping the junk value.
2057-
return is_array($containers) ? $containers : [];
2060+
// $containers is guaranteed an array here (normalized above; the refresh
2061+
// branch reassigns it from getDockerContainers()), so callers with typed
2062+
// array $info params never receive a scalar.
2063+
return $containers;
20582064
}
20592065

20602066
/**

0 commit comments

Comments
 (0)