From 028c6682935232c50ec729f38f97b2342f8363ad Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 15 Nov 2016 17:51:03 +0100 Subject: [PATCH 1/2] Do not cache version info in the sessions If the session is cleared and closed for whatever reason the loadVersion will write to the session anyways. This will lead to an exception. This should fix #1303 Signed-off-by: Roeland Jago Douma --- lib/private/legacy/util.php | 61 +++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index ecc8f05370..3ffd3bd3cc 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -66,6 +66,9 @@ class OC_Util { private static $rootMounted = false; private static $fsSetup = false; + /** @var array Local cache of version.php */ + private static $versionCache = null; + protected static function getAppManager() { return \OC::$server->getAppManager(); } @@ -397,7 +400,7 @@ class OC_Util { */ public static function getVersion() { OC_Util::loadVersion(); - return \OC::$server->getSession()->get('OC_Version'); + return self::$versionCache['OC_Version']; } /** @@ -407,7 +410,7 @@ class OC_Util { */ public static function getVersionString() { OC_Util::loadVersion(); - return \OC::$server->getSession()->get('OC_VersionString'); + return self::$versionCache['OC_VersionString']; } /** @@ -424,7 +427,7 @@ class OC_Util { */ public static function getChannel() { OC_Util::loadVersion(); - return \OC::$server->getSession()->get('OC_Channel'); + return self::$versionCache['OC_Channel']; } /** @@ -433,41 +436,41 @@ class OC_Util { */ public static function getBuild() { OC_Util::loadVersion(); - return \OC::$server->getSession()->get('OC_Build'); + return self::$versionCache['OC_Build']; } /** * @description load the version.php into the session as cache */ private static function loadVersion() { + if (self::$versionCache !== null) { + return; + } + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); - if (!\OC::$server->getSession()->exists('OC_Version') or OC::$server->getSession()->get('OC_Version_Timestamp') != $timestamp) { - require OC::$SERVERROOT . '/version.php'; - $session = \OC::$server->getSession(); - /** @var $timestamp int */ - $session->set('OC_Version_Timestamp', $timestamp); - /** @var $OC_Version string */ - $session->set('OC_Version', $OC_Version); - /** @var $OC_VersionString string */ - $session->set('OC_VersionString', $OC_VersionString); - /** @var $OC_Build string */ - $session->set('OC_Build', $OC_Build); + require OC::$SERVERROOT . '/version.php'; + /** @var $timestamp int */ + self::$versionCache['OC_Version_Timestamp'] = $timestamp; + /** @var $OC_Version string */ + self::$versionCache['OC_Version'] = $OC_Version; + /** @var $OC_VersionString string */ + self::$versionCache['OC_VersionString'] = $OC_VersionString; + /** @var $OC_Build string */ + self::$versionCache['OC_Build'] = $OC_Build; - // Allow overriding update channel + // Allow overriding update channel + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { + $channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel'); + } else { + /** @var $OC_Channel string */ + $channel = $OC_Channel; + } - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { - $channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel'); - } else { - /** @var $OC_Channel string */ - $channel = $OC_Channel; - } - - if (!is_null($channel)) { - $session->set('OC_Channel', $channel); - } else { - /** @var $OC_Channel string */ - $session->set('OC_Channel', $OC_Channel); - } + if (!is_null($channel)) { + self::$versionCache['OC_Channel'] = $channel; + } else { + /** @var $OC_Channel string */ + self::$versionCache['OC_Channel'] = $OC_Channel; } } From 7a8bf6ea263d339a47239a2e0b934f6b79b9bbec Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 15 Nov 2016 18:10:17 +0100 Subject: [PATCH 2/2] Fix tests Signed-off-by: Roeland Jago Douma --- lib/private/legacy/util.php | 24 +++++++++--------------- lib/public/Util.php | 1 - 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 3ffd3bd3cc..3bd5b5586a 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -427,6 +427,12 @@ class OC_Util { */ public static function getChannel() { OC_Util::loadVersion(); + + // Allow overriding update channel + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { + self::$versionCache['OC_Channel'] = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel'); + } + return self::$versionCache['OC_Channel']; } @@ -457,21 +463,9 @@ class OC_Util { self::$versionCache['OC_VersionString'] = $OC_VersionString; /** @var $OC_Build string */ self::$versionCache['OC_Build'] = $OC_Build; - - // Allow overriding update channel - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { - $channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel'); - } else { - /** @var $OC_Channel string */ - $channel = $OC_Channel; - } - - if (!is_null($channel)) { - self::$versionCache['OC_Channel'] = $channel; - } else { - /** @var $OC_Channel string */ - self::$versionCache['OC_Channel'] = $OC_Channel; - } + + /** @var $OC_Channel string */ + self::$versionCache['OC_Channel'] = $OC_Channel; } /** diff --git a/lib/public/Util.php b/lib/public/Util.php index 08661fd88c..8a7c899761 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -83,7 +83,6 @@ class Util { */ public static function setChannel($channel) { //Flush timestamp to reload version.php - \OC::$server->getSession()->set('OC_Version_Timestamp', 0); \OC::$server->getAppConfig()->setValue('core', 'OC_Channel', $channel); \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); }