Make LargeFileHelper.php faster by avoiding execs as much as possible
Signed-off-by: Marc Cousin <cousinmarc@gmail.com>
This commit is contained in:
parent
af2ecbbd5a
commit
184a0b97fc
|
@ -117,7 +117,7 @@ class LargeFileHelper {
|
||||||
public function getFileSizeViaCurl($fileName) {
|
public function getFileSizeViaCurl($fileName) {
|
||||||
if (\OC::$server->getIniWrapper()->getString('open_basedir') === '') {
|
if (\OC::$server->getIniWrapper()->getString('open_basedir') === '') {
|
||||||
$encodedFileName = rawurlencode($fileName);
|
$encodedFileName = rawurlencode($fileName);
|
||||||
$ch = curl_init("file://$encodedFileName");
|
$ch = curl_init("file:///$encodedFileName");
|
||||||
curl_setopt($ch, CURLOPT_NOBODY, true);
|
curl_setopt($ch, CURLOPT_NOBODY, true);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||||
|
@ -185,14 +185,22 @@ class LargeFileHelper {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getFileMtime($fullPath) {
|
public function getFileMtime($fullPath) {
|
||||||
|
try {
|
||||||
|
$result = filemtime($fullPath);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$result =- 1;
|
||||||
|
}
|
||||||
|
if ($result < 0) {
|
||||||
if (\OC_Helper::is_function_enabled('exec')) {
|
if (\OC_Helper::is_function_enabled('exec')) {
|
||||||
$os = strtolower(php_uname('s'));
|
$os = strtolower(php_uname('s'));
|
||||||
if (strpos($os, 'linux') !== false) {
|
if (strpos($os, 'linux') !== false) {
|
||||||
return $this->exec('stat -c %Y ' . escapeshellarg($fullPath));
|
return $this->exec('stat -c %Y ' . escapeshellarg($fullPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
|
||||||
return filemtime($fullPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function exec($cmd) {
|
protected function exec($cmd) {
|
||||||
|
|
Loading…
Reference in New Issue