diff options
author | Michael Gapczynski <mtgap@owncloud.com> | 2013-01-31 14:50:18 -0800 |
---|---|---|
committer | Michael Gapczynski <mtgap@owncloud.com> | 2013-01-31 14:50:18 -0800 |
commit | c3c9ad846273bc7cfe078eead9637da87cdfb7e9 (patch) | |
tree | 836f57ef0342c89cfd0aa1834e67f2a1a42d04e4 | |
parent | e21a0d210568306b83795459f5d3a90fd0ed804c (diff) | |
parent | 4b3563a3e318b296db310012ec375bd551c35e62 (diff) | |
download | nextcloud-server-c3c9ad846273bc7cfe078eead9637da87cdfb7e9.tar.gz nextcloud-server-c3c9ad846273bc7cfe078eead9637da87cdfb7e9.zip |
Merge pull request #1183 from owncloud/fix-388-stable45
backport of #1066 to stabe45
-rw-r--r-- | lib/filestorage.php | 2 | ||||
-rw-r--r-- | lib/filestorage/local.php | 47 | ||||
-rw-r--r-- | lib/helper.php | 56 |
3 files changed, 86 insertions, 19 deletions
diff --git a/lib/filestorage.php b/lib/filestorage.php index 5bfd09253d5..76635712281 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -21,7 +21,7 @@ */ /** - * Provde a common interface to all different storage options + * Provide a common interface to all different storage options */ abstract class OC_Filestorage{ abstract public function __construct($parameters); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 80aa548047c..7a78d4ec8e8 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -29,7 +29,15 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return is_file($this->datadir.$path); } public function stat($path) { - return stat($this->datadir.$path); + $fullPath = $this->datadir . $path; + $statResult = stat($fullPath); + + if ($statResult['size'] < 0) { + $size = self::getFileSizeFromOS($fullPath); + $statResult['size'] = $size; + $statResult[7] = $size; + } + return $statResult; } public function filetype($path) { $filetype=filetype($this->datadir.$path); @@ -42,7 +50,13 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ if($this->is_dir($path)) { return 0; }else{ - return filesize($this->datadir.$path); + $fullPath = $this->datadir . $path; + $fileSize = filesize($fullPath); + if ($fileSize < 0) { + return self::getFileSizeFromOS($fullPath); + } + + return $fileSize; } } public function isReadable($path) { @@ -156,6 +170,34 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ return $return; } + 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 (float)exec('stat -f %z ' . escapeshellarg($fullPath)); + } + } else { + if (strpos($name, 'linux') !== false) { + if (\OC_Helper::is_function_enabled('exec')) { + return (float)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 0; + } + public function hash($path,$type,$raw=false) { return hash_file($type,$this->datadir.$path,$raw); } @@ -190,6 +232,7 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{ /** * check if a file or folder has been updated since $time + * @param string $path * @param int $time * @return bool */ diff --git a/lib/helper.php b/lib/helper.php index b35770dd9dc..3cec45a0953 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -114,6 +114,7 @@ class OC_Helper { /** * @brief Creates an absolute url for remote use * @param string $service id + * @param bool $add_slash * @return string the url * * Returns a absolute url to the given service. @@ -125,6 +126,7 @@ class OC_Helper { /** * @brief Creates an absolute url for public use * @param string $service id + * @param bool $add_slash * @return string the url * * Returns a absolute url to the given service. @@ -442,12 +444,14 @@ class OC_Helper { } /** - * detect if a given program is found in the search PATH - * - * @param string $program name - * @param string $optional search path, defaults to $PATH - * @return bool true if executable program found in path - */ + * detect if a given program is found in the search PATH + * + * @param $name + * @param bool $path + * @internal param string $program name + * @internal param string $optional search path, defaults to $PATH + * @return bool true if executable program found in path + */ public static function canExecute($name, $path = false) { // path defaults to PATH from environment if not set if ($path === false) { @@ -637,16 +641,16 @@ class OC_Helper { } /** - * @brief replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. - * - * @param string $input The input string. .Opposite to the PHP build-in function does not accept an array. - * @param string $replacement The replacement string. - * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. - * @param int $length Length of the part to be replaced - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @return string - * - */ + * @brief replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. + * + * @param $string + * @param string $replacement The replacement string. + * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. + * @param int $length Length of the part to be replaced + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @internal param string $input The input string. .Opposite to the PHP build-in function does not accept an array. + * @return string + */ public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') { $start = intval($start); $length = intval($length); @@ -704,4 +708,24 @@ class OC_Helper { return false; } + + /** + * Checks if a function is available + * @param string $function_name + * @return bool + */ + public static function is_function_enabled($function_name) { + if (!function_exists($function_name)) { + return false; + } + $disabled = explode(', ', ini_get('disable_functions')); + if (in_array($function_name, $disabled)) { + return false; + } + $disabled = explode(', ', ini_get('suhosin.executor.func.blacklist')); + if (in_array($function_name, $disabled)) { + return false; + } + return true; + } } |