From cfc0d9249bf53449dc8daed9c9811dc78fe7086c Mon Sep 17 00:00:00 2001 From: Boris Rybalkin Date: Thu, 29 Sep 2016 10:10:35 +0100 Subject: [PATCH 1/3] fixing php 32 bit (arm) filemtime on large file issue (#18971) (#25428) * fixing php 32 bit (arm) filemtime on large file issue (#18971) * cast to int --- lib/private/Files/Storage/Local.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 0d63fd46ecca8..9720162164505 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -173,8 +173,15 @@ public function file_exists($path) { } public function filemtime($path) { - clearstatcache($this->getSourcePath($path)); - return $this->file_exists($path) ? filemtime($this->getSourcePath($path)) : false; + $fullPath = $this->getSourcePath($path); + clearstatcache($fullPath); + if (!$this->file_exists($path)) { + return false; + } + if (PHP_INT_SIZE === 4) { + return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath)); + } + return filemtime($fullPath); } public function touch($path, $mtime = null) { From 459477e2c3981d28605f6cb304afedd8ec6f5a3b Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 25 Oct 2016 11:42:16 +0200 Subject: [PATCH 2/3] Move function to LargeFileHelper Signed-off-by: Lukas Reschke --- lib/private/Files/Storage/Local.php | 3 ++- lib/private/LargeFileHelper.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 9720162164505..294e3d0a34cd2 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -179,7 +179,8 @@ public function filemtime($path) { return false; } if (PHP_INT_SIZE === 4) { - return (int) exec ('stat -c %Y '. escapeshellarg ($fullPath)); + $helper = new \OC\LargeFileHelper(); + return $helper->getFileMtime($fullPath); } return filemtime($fullPath); } diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index 9d0fe864033b5..b75cdcc210eee 100644 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -187,6 +187,20 @@ public function getFileSizeNative($filename) { return $result; } + /** + * Returns the current mtime for $fullPath + * + * @param string $fullPath + * @return int + */ + public function getFileMtime($fullPath) { + if (\OC_Helper::is_function_enabled('exec')) { + return $this->exec('stat -c %Y ' . escapeshellarg($fullPath)); + } + + return filemtime($fullPath); + } + protected function exec($cmd) { $result = trim(exec($cmd)); return ctype_digit($result) ? 0 + $result : null; From 62bb991050b20b443f8f11cf04e0a331648d2519 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 25 Oct 2016 12:01:03 +0200 Subject: [PATCH 3/3] Add check for linux os Signed-off-by: Lukas Reschke --- lib/private/LargeFileHelper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/LargeFileHelper.php b/lib/private/LargeFileHelper.php index b75cdcc210eee..258e53acf9d67 100644 --- a/lib/private/LargeFileHelper.php +++ b/lib/private/LargeFileHelper.php @@ -1,6 +1,7 @@ * * @author Andreas Fischer * @author Lukas Reschke @@ -195,7 +196,10 @@ public function getFileSizeNative($filename) { */ public function getFileMtime($fullPath) { if (\OC_Helper::is_function_enabled('exec')) { - return $this->exec('stat -c %Y ' . escapeshellarg($fullPath)); + $os = strtolower(php_uname('s')); + if (strpos($os, 'linux') !== false) { + return $this->exec('stat -c %Y ' . escapeshellarg($fullPath)); + } } return filemtime($fullPath);