summaryrefslogtreecommitdiffstats
path: root/lib/private/largefilehelper.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2014-02-18 12:57:44 +0100
committerAndreas Fischer <bantu@owncloud.com>2014-05-29 16:26:02 +0200
commit0417e52134e87c379b3b4c22a53a0c06a711baef (patch)
tree6677630fd4b4e9b94f8fd02a8b399b2fea142f07 /lib/private/largefilehelper.php
parentfb4556033a9d39698dbc15b59f3ba76ef6510e33 (diff)
downloadnextcloud-server-0417e52134e87c379b3b4c22a53a0c06a711baef.tar.gz
nextcloud-server-0417e52134e87c379b3b4c22a53a0c06a711baef.zip
Increase file size limit from 2 GiB to 4 GiB when workarounds are unavailable.
Diffstat (limited to 'lib/private/largefilehelper.php')
-rw-r--r--lib/private/largefilehelper.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/private/largefilehelper.php b/lib/private/largefilehelper.php
index 08869d7c82a..3d15e786042 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;