[Pkg-owncloud-commits] [owncloud] 285/394: backport of #1066 to stabe45

David Prévot taffit at alioth.debian.org
Fri Nov 8 23:12:29 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag v4.5.10
in repository owncloud.

commit 4b3563a3e318b296db310012ec375bd551c35e62
Author: Thomas Mueller <thomas.mueller at tmit.eu>
Date:   Mon Jan 14 22:58:32 2013 +0100

    backport of #1066 to stabe45
---
 lib/filestorage.php       |    2 +-
 lib/filestorage/local.php |   47 +++++++++++++++++++++++++++++++++++--
 lib/helper.php            |   56 ++++++++++++++++++++++++++++++++-------------
 3 files changed, 86 insertions(+), 19 deletions(-)

diff --git a/lib/filestorage.php b/lib/filestorage.php
index 5bfd092..7663571 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 80aa548..7a78d4e 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 96242a8..62ad936 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.
@@ -441,12 +443,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) {
@@ -636,16 +640,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);
@@ -703,4 +707,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;
+	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list