Merge pull request #9490 from marco44/faster_large_filehelper_32bits

Make LargeFileHelper.php faster by avoiding execs as much as possible
This commit is contained in:
Roeland Jago Douma 2018-05-18 21:09:17 +02:00 committed by GitHub
commit 03a6f8e14e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

20
lib/private/LargeFileHelper.php Normal file → Executable file
View File

@ -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) {