[Pkg-owncloud-commits] [owncloud] 134/199: Increase file size limit from 2 GiB to 4 GiB when workarounds are unavailable.

David Prévot taffit at moszumanska.debian.org
Sun Jun 1 18:53:18 UTC 2014


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

taffit pushed a commit to branch master
in repository owncloud.

commit 0417e52134e87c379b3b4c22a53a0c06a711baef
Author: Andreas Fischer <bantu at owncloud.com>
Date:   Tue Feb 18 12:57:44 2014 +0100

    Increase file size limit from 2 GiB to 4 GiB when workarounds are unavailable.
---
 lib/private/files/storage/local.php       |  5 +----
 lib/private/files/storage/mappedlocal.php |  5 +----
 lib/private/largefilehelper.php           | 23 ++++++++++++++++++++++-
 tests/lib/largefilehelpergetfilesize.php  |  7 +++++++
 4 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php
index f4bc508..e33747b 100644
--- a/lib/private/files/storage/local.php
+++ b/lib/private/files/storage/local.php
@@ -112,10 +112,7 @@ if (\OC_Util::runningOnWindows()) {
 			$fullPath = $this->datadir . $path;
 			if (PHP_INT_SIZE === 4) {
 				$helper = new \OC\LargeFileHelper;
-				$filesize = $helper->getFilesize($fullPath);
-				if (!is_null($filesize)) {
-					return $filesize;
-				}
+				return $helper->getFilesize($fullPath);
 			}
 			return filesize($fullPath);
 		}
diff --git a/lib/private/files/storage/mappedlocal.php b/lib/private/files/storage/mappedlocal.php
index f38b48d..ea4deaa 100644
--- a/lib/private/files/storage/mappedlocal.php
+++ b/lib/private/files/storage/mappedlocal.php
@@ -134,10 +134,7 @@ class MappedLocal extends \OC\Files\Storage\Common {
 		$fullPath = $this->buildPath($path);
 		if (PHP_INT_SIZE === 4) {
 			$helper = new \OC\LargeFileHelper;
-			$filesize = $helper->getFilesize($fullPath);
-			if (!is_null($filesize)) {
-				return $filesize;
-			}
+			return $helper->getFilesize($fullPath);
 		}
 		return filesize($fullPath);
 	}
diff --git a/lib/private/largefilehelper.php b/lib/private/largefilehelper.php
index 08869d7..3d15e78 100644
--- a/lib/private/largefilehelper.php
+++ b/lib/private/largefilehelper.php
@@ -83,7 +83,7 @@ class LargeFileHelper {
 		if (!is_null($filesize)) {
 			return $filesize;
 		}
-		return null;
+		return $this->getFilesizeNative($filename);
 	}
 
 	/**
@@ -159,6 +159,27 @@ class LargeFileHelper {
 		return null;
 	}
 
+	/**
+	* @brief Gets the filesize via a filesize() call and converts negative
+	*        signed int to positive float. As the result of filesize() will
+	*        wrap around after a filesize of 2^32 bytes = 4 GiB, this should
+	*        only be used as a last resort.
+	*
+	* @param string $filename Path to the file.
+	*
+	* @return int|float Number of bytes as number (float or int).
+	*/
+	public function getFilesizeNative($filename) {
+		$result = filesize($filename);
+		if ($result < 0) {
+			// For filesizes between 2 GiB and 4 GiB, filesize() will return a
+			// negative int, as the PHP data type int is signed. Interpret the
+			// returned int as an unsigned integer and put it into a float.
+			return (float) sprintf('%u', $result);
+		}
+		return $result;
+	}
+
 	protected function exec($cmd) {
 		$result = trim(exec($cmd));
 		return ctype_digit($result) ? 0 + $result : null;
diff --git a/tests/lib/largefilehelpergetfilesize.php b/tests/lib/largefilehelpergetfilesize.php
index 001f636..699dd68 100644
--- a/tests/lib/largefilehelpergetfilesize.php
+++ b/tests/lib/largefilehelpergetfilesize.php
@@ -59,4 +59,11 @@ class LargeFileHelperGetFilesize extends \PHPUnit_Framework_TestCase {
 			$this->helper->getFilesizeViaExec($this->filename)
 		);
 	}
+
+	public function testGetFilesizeNative() {
+		$this->assertSame(
+			$this->filesize,
+			$this->helper->getFilesizeNative($this->filename)
+		);
+	}
 }

-- 
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