summaryrefslogtreecommitdiffstats
path: root/lib/private/files/storage/local.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2014-02-09 01:25:33 +0100
committerAndreas Fischer <bantu@owncloud.com>2014-05-29 16:26:01 +0200
commitc8fa1fd68784c48c1df537310f16d6753f79b029 (patch)
treeda53d4744785eafbfc77e50a835904eb9e5f6d32 /lib/private/files/storage/local.php
parent3f8f8027d25ab39283d0ab13afcf7252dde8f240 (diff)
downloadnextcloud-server-c8fa1fd68784c48c1df537310f16d6753f79b029.tar.gz
nextcloud-server-c8fa1fd68784c48c1df537310f16d6753f79b029.zip
Refactor Large File handling code.
Diffstat (limited to 'lib/private/files/storage/local.php')
-rw-r--r--lib/private/files/storage/local.php98
1 files changed, 8 insertions, 90 deletions
diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php
index 7fa748a7fd7..883a69d7681 100644
--- a/lib/private/files/storage/local.php
+++ b/lib/private/files/storage/local.php
@@ -89,9 +89,8 @@ if (\OC_Util::runningOnWindows()) {
public function stat($path) {
$fullPath = $this->datadir . $path;
$statResult = stat($fullPath);
-
- $filesize = self::getFileSizeWithTricks($fullPath);
- if (!is_null($filesize)) {
+ if (PHP_INT_SIZE === 4) {
+ $filesize = $this->filesize($path);
$statResult['size'] = $filesize;
$statResult[7] = $filesize;
}
@@ -109,16 +108,16 @@ if (\OC_Util::runningOnWindows()) {
public function filesize($path) {
if ($this->is_dir($path)) {
return 0;
- } else {
- $fullPath = $this->datadir . $path;
-
- $filesize = self::getFileSizeWithTricks($fullPath);
+ }
+ $fullPath = $this->datadir . $path;
+ if (PHP_INT_SIZE === 4) {
+ $helper = new \OC\LargeFileHelper;
+ $filesize = $helper->getFilesize($fullPath);
if (!is_null($filesize)) {
return $filesize;
}
-
- return filesize($fullPath);
}
+ return filesize($fullPath);
}
public function isReadable($path) {
@@ -221,87 +220,6 @@ if (\OC_Util::runningOnWindows()) {
return $return;
}
- /**
- * @brief Tries to get the filesize via various workarounds if necessary.
- * @param string $fullPath
- * @return mixed Number of bytes on success and workaround necessary, null otherwise.
- */
- private static function getFileSizeWithTricks($fullPath) {
- if (PHP_INT_SIZE === 4) {
- // filesize() and stat() are unreliable on 32bit systems
- // for big files.
- // In some cases they cause an E_WARNING and return false,
- // in some other cases they silently wrap around at 2^32,
- // i.e. e.g. report 674347008 bytes instead of 4969314304.
- $filesize = self::getFileSizeFromCurl($fullPath);
- if (!is_null($filesize)) {
- return $filesize;
- }
- $filesize = self::getFileSizeFromOS($fullPath);
- if (!is_null($filesize)) {
- return $filesize;
- }
- }
-
- return null;
- }
-
- /**
- * @brief Tries to get the filesize via a CURL HEAD request.
- * @param string $fullPath
- * @return mixed Number of bytes on success, null otherwise.
- */
- private static function getFileSizeFromCurl($fullPath) {
- if (function_exists('curl_init')) {
- $ch = curl_init("file://$fullPath");
- curl_setopt($ch, CURLOPT_NOBODY, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, true);
- $data = curl_exec($ch);
- curl_close($ch);
- if ($data !== false) {
- $matches = array();
- preg_match('/Content-Length: (\d+)/', $data, $matches);
- if (isset($matches[1])) {
- return 0 + $matches[1];
- }
- }
- }
-
- return null;
- }
-
- /**
- * @brief Tries to get the filesize via COM and exec().
- * @param string $fullPath
- * @return mixed Number of bytes on success, null otherwise.
- */
- private static function getFileSizeFromOS($fullPath) {
- $name = strtolower(php_uname('s'));
- // Windows OS: we use COM to access the filesystem
- if (strpos($name, 'win') !== false) {
- if (class_exists('COM')) {
- $fsobj = new \COM("Scripting.FileSystemObject");
- $f = $fsobj->GetFile($fullPath);
- return $f->Size;
- }
- } else if (strpos($name, 'bsd') !== false) {
- if (\OC_Helper::is_function_enabled('exec')) {
- return 0 + exec('stat -f %z ' . escapeshellarg($fullPath));
- }
- } else if (strpos($name, 'linux') !== false) {
- if (\OC_Helper::is_function_enabled('exec')) {
- return 0 + exec('stat -c %s ' . escapeshellarg($fullPath));
- }
- } else {
- \OC_Log::write('core',
- 'Unable to determine file size of "' . $fullPath . '". Unknown OS: ' . $name,
- \OC_Log::ERROR);
- }
-
- return null;
- }
-
public function hash($type, $path, $raw = false) {
return hash_file($type, $this->datadir . $path, $raw);
}