From 32fd0919c1fc546bf84b5ce2da54dd59c57f4085 Mon Sep 17 00:00:00 2001 From: marco44 Date: Wed, 16 May 2018 12:59:58 +0200 Subject: [PATCH] Make LargeFileHelper.php faster by avoiding execs as much as possible Signed-off-by: Marc Cousin --- lib/private/LargeFileHelper.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) mode change 100644 => 100755 lib/private/LargeFileHelper.php diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php old mode 100644 new mode 100755 index ea848f8362..d6dcbeedb4 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -117,7 +117,7 @@ class LargeFileHelper { public function getFileSizeViaCurl($fileName) { if (\OC::$server->getIniWrapper()->getString('open_basedir') === '') { $encodedFileName = rawurlencode($fileName); - $ch = curl_init("file://$encodedFileName"); + $ch = curl_init("file:///$encodedFileName"); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); @@ -185,14 +185,22 @@ class LargeFileHelper { * @return int */ public function getFileMtime($fullPath) { - if (\OC_Helper::is_function_enabled('exec')) { - $os = strtolower(php_uname('s')); - if (strpos($os, 'linux') !== false) { - return $this->exec('stat -c %Y ' . escapeshellarg($fullPath)); + try { + $result = filemtime($fullPath); + } catch (\Exception $e) { + $result =- 1; + } + if ($result < 0) { + if (\OC_Helper::is_function_enabled('exec')) { + $os = strtolower(php_uname('s')); + if (strpos($os, 'linux') !== false) { + return $this->exec('stat -c %Y ' . escapeshellarg($fullPath)); + } } } + return $result; + - return filemtime($fullPath); } protected function exec($cmd) {