Skip to content

Commit

Permalink
Merge pull request #9656 from nextcloud/backport/9490/stable13
Browse files Browse the repository at this point in the history
[stable13] Make LargeFileHelper.php faster by avoiding execs as much as possible
  • Loading branch information
MorrisJobke committed May 29, 2018
2 parents de539c6 + 184a0b9 commit b3e9e36
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/private/LargeFileHelper.php 100644 → 100755
Expand Up @@ -117,7 +117,7 @@ public function getFileSize($filename) {
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);
Expand Down Expand Up @@ -185,14 +185,22 @@ public function getFileSizeNative($filename) {
* @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) {
Expand Down

0 comments on commit b3e9e36

Please sign in to comment.