From df46d150f6bd3d1b3afd41df8b3c6a77b0537c22 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 22 Aug 2017 08:28:31 +0545 Subject: [PATCH 1/2] BSD case for 32 bit filemtime and install warning --- lib/private/Files/Storage/Local.php | 7 ++++++- lib/private/LargeFileHelper.php | 11 ++--------- lib/private/Setup.php | 12 +++++++++--- lib/private/legacy/util.php | 26 ++++++++++++++++++++++---- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index b61b902de2ec..d1cc475225b5 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -180,7 +180,12 @@ public function filemtime($path) { return false; } if (PHP_INT_SIZE === 4) { - return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath)); + if (\OC_Util::runningOn('linux')) { + return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath)); + } else if (\OC_Util::runningOn('bsd') || \OC_Util::runningOn('mac')) { + return (int) exec ('stat -f %m '. escapeshellarg ($fullPath)); + } + return false; } return filemtime($fullPath); } diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index 6f1cfacdb148..df142dd192fc 100644 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -142,19 +142,12 @@ public function getFileSizeViaCurl($fileName) { */ public function getFileSizeViaExec($filename) { if (\OC_Helper::is_function_enabled('exec')) { - $os = strtolower(php_uname('s')); $arg = escapeshellarg($filename); $result = null; - if (strpos($os, 'linux') !== false) { + if (\OC_Util::runningOn('linux')) { $result = $this->exec("stat -c %s $arg"); - } else if (strpos($os, 'bsd') !== false || strpos($os, 'darwin') !== false) { + } else if (\OC_Util::runningOn('bsd') || \OC_Util::runningOn('mac')) { $result = $this->exec("stat -f %z $arg"); - } else if (strpos($os, 'win') !== false) { - $result = $this->exec("for %F in ($arg) do @echo %~zF"); - if (is_null($result)) { - // PowerShell - $result = $this->exec("(Get-Item $arg).length"); - } } return $result; } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 3abbb3d8cfe1..b54d2e3f0cc3 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -203,12 +203,18 @@ public function getSystemInfo($allowAllDatabases = false) { \OC\Setup::protectDataDirectory(); } - if (\OC_Util::runningOnMac()) { + if (!\OC_Util::runningOn('linux')) { + if (\OC_Util::runningOn('mac')) { + $os = 'Mac OS X'; + } else { + $os = PHP_OS; + } + $errors[] = [ 'error' => $this->l10n->t( - 'Mac OS X is not supported and %s will not work properly on this platform. ' . + '%s is not supported and %s will not work properly on this platform. ' . 'Use it at your own risk! ', - $this->defaults->getName() + [$os, $this->defaults->getName()] ), 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.') ]; diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index c44f828a3f8d..f960a94fc00c 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -1250,12 +1250,30 @@ public static function obEnd() { } /** - * Checks whether the server is running on Mac OS X + * Checks whether the server is running on the given OS type * - * @return bool true if running on Mac OS X, false otherwise + * @param string $osType linux|mac|bsd + * @return bool true if running on that OS type, false otherwise */ - public static function runningOnMac() { - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); + public static function runningOn($osType) { + $osType = strtolower($osType); + + switch($osType) { + case 'linux': + return (strtolower(substr(PHP_OS, 0, 5)) === 'linux'); + break; + + case 'mac': + return (strtolower(substr(PHP_OS, 0, 6)) === 'darwin'); + break; + + case 'bsd': + return (strpos(strtolower(PHP_OS), 'bsd') !== false); + break; + + default; + return false; + } } /** From b2a7fa3bb73397aa375e489829e2e3003bffa2c9 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 23 Aug 2017 21:40:49 +0545 Subject: [PATCH 2/2] refactor runningOn() --- lib/private/legacy/util.php | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index f960a94fc00c..303066055930 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -1252,27 +1252,16 @@ public static function obEnd() { /** * Checks whether the server is running on the given OS type * - * @param string $osType linux|mac|bsd + * @param string $osType linux|mac|bsd etc * @return bool true if running on that OS type, false otherwise */ public static function runningOn($osType) { - $osType = strtolower($osType); + $osType = strtolower($osType) === 'mac' ? 'darwin' : strtolower($osType); - switch($osType) { - case 'linux': - return (strtolower(substr(PHP_OS, 0, 5)) === 'linux'); - break; - - case 'mac': - return (strtolower(substr(PHP_OS, 0, 6)) === 'darwin'); - break; - - case 'bsd': - return (strpos(strtolower(PHP_OS), 'bsd') !== false); - break; - - default; - return false; + if ($osType === 'bsd') { + return (strpos(strtolower(PHP_OS), $osType) !== false); + } else { + return (strtolower(substr(PHP_OS, 0, strlen($osType))) === $osType); } }