aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2019-02-28 13:49:27 +0100
committerGitHub <noreply@github.com>2019-02-28 13:49:27 +0100
commit7519a9a9903565f53d6b656fbd328a83df6011b9 (patch)
treef47193d9c8b4081618af605f817a0f70652f21ea /lib
parentc30ceddcce76ca441481f5e7eed4601df19c505d (diff)
parent8fc47c6f002dd47518cea34ec5fe113fa5b915b7 (diff)
downloadnextcloud-server-7519a9a9903565f53d6b656fbd328a83df6011b9.tar.gz
nextcloud-server-7519a9a9903565f53d6b656fbd328a83df6011b9.zip
Merge pull request #14412 from nextcloud/fileinfo-raw-size
add option to get raw size (without submounts) from fileinfo
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/FileInfo.php18
-rw-r--r--lib/private/Files/Node/LazyRoot.php2
-rw-r--r--lib/private/Files/Node/Node.php5
-rw-r--r--lib/private/Files/Node/NonExistingFile.php4
-rw-r--r--lib/private/Files/Node/NonExistingFolder.php4
-rw-r--r--lib/private/Files/Node/Root.php3
-rw-r--r--lib/public/Files/FileInfo.php3
-rw-r--r--lib/public/Files/Node.php3
8 files changed, 29 insertions, 13 deletions
diff --git a/lib/private/Files/FileInfo.php b/lib/private/Files/FileInfo.php
index 575af56ceb5..19b95cd0355 100644
--- a/lib/private/Files/FileInfo.php
+++ b/lib/private/Files/FileInfo.php
@@ -81,6 +81,13 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
private $subMountsUsed = false;
/**
+ * The size of the file/folder without any sub mount
+ *
+ * @var int
+ */
+ private $rawSize = 0;
+
+ /**
* @param string|boolean $path
* @param Storage\Storage $storage
* @param string $internalPath
@@ -95,6 +102,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
$this->data = $data;
$this->mount = $mount;
$this->owner = $owner;
+ $this->rawSize = $this->data['size'] ?? 0;
}
public function offsetSet($offset, $value) {
@@ -194,9 +202,13 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
/**
* @return int
*/
- public function getSize() {
- $this->updateEntryfromSubMounts();
- return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
+ public function getSize($includeMounts = true) {
+ if ($includeMounts) {
+ $this->updateEntryfromSubMounts();
+ return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
+ } else {
+ return $this->rawSize;
+ }
}
/**
diff --git a/lib/private/Files/Node/LazyRoot.php b/lib/private/Files/Node/LazyRoot.php
index 389a1a9f0ff..01b4ca52765 100644
--- a/lib/private/Files/Node/LazyRoot.php
+++ b/lib/private/Files/Node/LazyRoot.php
@@ -214,7 +214,7 @@ class LazyRoot implements IRootFolder {
/**
* @inheritDoc
*/
- public function getSize() {
+ public function getSize($includeMounts = true) {
return $this->__call(__FUNCTION__, func_get_args());
}
diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php
index 590f1080617..41e8bf75242 100644
--- a/lib/private/Files/Node/Node.php
+++ b/lib/private/Files/Node/Node.php
@@ -190,12 +190,13 @@ class Node implements \OCP\Files\Node {
}
/**
+ * @param bool $includeMounts
* @return int
* @throws InvalidPathException
* @throws NotFoundException
*/
- public function getSize() {
- return $this->getFileInfo()->getSize();
+ public function getSize($includeMounts = true) {
+ return $this->getFileInfo()->getSize($includeMounts);
}
/**
diff --git a/lib/private/Files/Node/NonExistingFile.php b/lib/private/Files/Node/NonExistingFile.php
index fbfb67749bb..5183102483f 100644
--- a/lib/private/Files/Node/NonExistingFile.php
+++ b/lib/private/Files/Node/NonExistingFile.php
@@ -66,9 +66,9 @@ class NonExistingFile extends File {
}
}
- public function getSize() {
+ public function getSize($includeMounts = true) {
if ($this->fileInfo) {
- return parent::getSize();
+ return parent::getSize($includeMounts);
} else {
throw new NotFoundException();
}
diff --git a/lib/private/Files/Node/NonExistingFolder.php b/lib/private/Files/Node/NonExistingFolder.php
index efc359181c6..f6a1794a531 100644
--- a/lib/private/Files/Node/NonExistingFolder.php
+++ b/lib/private/Files/Node/NonExistingFolder.php
@@ -67,9 +67,9 @@ class NonExistingFolder extends Folder {
}
}
- public function getSize() {
+ public function getSize($includeMounts = true) {
if ($this->fileInfo) {
- return parent::getSize();
+ return parent::getSize($includeMounts);
} else {
throw new NotFoundException();
}
diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php
index 189c2863a34..390d29edb31 100644
--- a/lib/private/Files/Node/Root.php
+++ b/lib/private/Files/Node/Root.php
@@ -282,9 +282,10 @@ class Root extends Folder implements IRootFolder {
}
/**
+ * @param bool $includeMounts
* @return int
*/
- public function getSize() {
+ public function getSize($includeMounts = true) {
return null;
}
diff --git a/lib/public/Files/FileInfo.php b/lib/public/Files/FileInfo.php
index e25a47e83cd..c256f0980f0 100644
--- a/lib/public/Files/FileInfo.php
+++ b/lib/public/Files/FileInfo.php
@@ -81,10 +81,11 @@ interface FileInfo {
/**
* Get the size in bytes for the file or folder
*
+ * @param bool $includeMounts whether or not to include the size of any sub mounts, since 16.0.0
* @return int
* @since 7.0.0
*/
- public function getSize();
+ public function getSize($includeMounts = true);
/**
* Get the last modified date as timestamp for the file or folder
diff --git a/lib/public/Files/Node.php b/lib/public/Files/Node.php
index 59bd0e193c6..016b217afc3 100644
--- a/lib/public/Files/Node.php
+++ b/lib/public/Files/Node.php
@@ -136,12 +136,13 @@ interface Node extends FileInfo {
/**
* Get the size of the file or folder in bytes
*
+ * @param bool $includeMounts
* @return int
* @throws InvalidPathException
* @throws NotFoundException
* @since 6.0.0
*/
- public function getSize();
+ public function getSize($includeMounts = true);
/**
* Get the Etag of the file or folder