summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-12-04 16:34:30 +0100
committerMorris Jobke <hey@morrisjobke.de>2014-12-04 16:34:30 +0100
commitf3213571bb2609a7f279fd5254f872083b3ea91a (patch)
treefe261dd9ba224efd9b9c28968ec7a2d28503fcdf /lib
parentb8a2fdaa21ef84ef778b6b38c5d57f0babf896c5 (diff)
parent672495a1a31c71880fe93fce3a8134278a48ca7a (diff)
downloadnextcloud-server-f3213571bb2609a7f279fd5254f872083b3ea91a.tar.gz
nextcloud-server-f3213571bb2609a7f279fd5254f872083b3ea91a.zip
Merge pull request #12616 from owncloud/node-fileinfo
make \OC\Files\Node\Node implement the FileInfo interface
Diffstat (limited to 'lib')
-rw-r--r--lib/private/files/node/file.php10
-rw-r--r--lib/private/files/node/folder.php7
-rw-r--r--lib/private/files/node/node.php71
3 files changed, 60 insertions, 28 deletions
diff --git a/lib/private/files/node/file.php b/lib/private/files/node/file.php
index 81e251c20b8..1c47294cdae 100644
--- a/lib/private/files/node/file.php
+++ b/lib/private/files/node/file.php
@@ -34,6 +34,7 @@ class File extends Node implements \OCP\Files\File {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
$this->sendHooks(array('preWrite'));
$this->view->file_put_contents($this->path, $data);
+ $this->fileInfo = null;
$this->sendHooks(array('postWrite'));
} else {
throw new NotPermittedException();
@@ -41,13 +42,6 @@ class File extends Node implements \OCP\Files\File {
}
/**
- * @return string
- */
- public function getMimeType() {
- return $this->view->getMimeType($this->path);
- }
-
- /**
* @param string $mode
* @return resource
* @throws \OCP\Files\NotPermittedException
@@ -94,6 +88,7 @@ class File extends Node implements \OCP\Files\File {
$nonExisting = new NonExistingFile($this->root, $this->view, $this->path);
$this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
$this->exists = false;
+ $this->fileInfo = null;
} else {
throw new NotPermittedException();
}
@@ -138,6 +133,7 @@ class File extends Node implements \OCP\Files\File {
$this->root->emit('\OC\Files', 'postRename', array($this, $targetNode));
$this->root->emit('\OC\Files', 'postWrite', array($targetNode));
$this->path = $targetPath;
+ $this->fileInfo = null;
return $targetNode;
} else {
throw new NotPermittedException();
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index 83e20871528..54a699be532 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -321,13 +321,6 @@ class Folder extends Node implements \OCP\Files\Folder {
return $this->view->free_space($this->path);
}
- /**
- * @return bool
- */
- public function isCreatable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
- }
-
public function delete() {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
$this->sendHooks(array('preDelete'));
diff --git a/lib/private/files/node/node.php b/lib/private/files/node/node.php
index c52f5bbd54f..b80db28e8ec 100644
--- a/lib/private/files/node/node.php
+++ b/lib/private/files/node/node.php
@@ -8,10 +8,10 @@
namespace OC\Files\Node;
-use OCP\Files\NotFoundException;
+use OCP\Files\FileInfo;
use OCP\Files\NotPermittedException;
-class Node implements \OCP\Files\Node {
+class Node implements \OCP\Files\Node, FileInfo {
/**
* @var \OC\Files\View $view
*/
@@ -28,6 +28,11 @@ class Node implements \OCP\Files\Node {
protected $path;
/**
+ * @var \OCP\Files\FileInfo
+ */
+ protected $fileInfo;
+
+ /**
* @param \OC\Files\View $view
* @param \OC\Files\Node\Root $root
* @param string $path
@@ -38,6 +43,13 @@ class Node implements \OCP\Files\Node {
$this->path = $path;
}
+ private function getFileInfo() {
+ if (!$this->fileInfo) {
+ $this->fileInfo = $this->view->getFileInfo($this->path);
+ }
+ return $this->fileInfo;
+ }
+
/**
* @param string[] $hooks
*/
@@ -85,6 +97,12 @@ class Node implements \OCP\Files\Node {
$this->sendHooks(array('preTouch'));
$this->view->touch($this->path, $mtime);
$this->sendHooks(array('postTouch'));
+ if ($this->fileInfo) {
+ if (is_null($mtime)) {
+ $mtime = time();
+ }
+ $this->fileInfo['mtime'] = $mtime;
+ }
} else {
throw new NotPermittedException();
}
@@ -118,8 +136,7 @@ class Node implements \OCP\Files\Node {
* @return int
*/
public function getId() {
- $info = $this->view->getFileInfo($this->path);
- return $info['fileid'];
+ return $this->getFileInfo()->getId();
}
/**
@@ -133,58 +150,60 @@ class Node implements \OCP\Files\Node {
* @return int
*/
public function getMTime() {
- return $this->view->filemtime($this->path);
+ return $this->getFileInfo()->getMTime();
}
/**
* @return int
*/
public function getSize() {
- return $this->view->filesize($this->path);
+ return $this->getFileInfo()->getSize();
}
/**
* @return string
*/
public function getEtag() {
- $info = $this->view->getFileInfo($this->path);
- return $info['etag'];
+ return $this->getFileInfo()->getEtag();
}
/**
* @return int
*/
public function getPermissions() {
- $info = $this->view->getFileInfo($this->path);
- return $info['permissions'];
+ return $this->getFileInfo()->getPermissions();
}
/**
* @return bool
*/
public function isReadable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
+ return $this->getFileInfo()->isReadable();
}
/**
* @return bool
*/
public function isUpdateable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
+ return $this->getFileInfo()->isUpdateable();
}
/**
* @return bool
*/
public function isDeletable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
+ return $this->getFileInfo()->isDeletable();
}
/**
* @return bool
*/
public function isShareable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
+ return $this->getFileInfo()->isShareable();
+ }
+
+ public function isCreatable() {
+ return $this->getFileInfo()->isCreatable();
}
/**
@@ -240,4 +259,28 @@ class Node implements \OCP\Files\Node {
}
return true;
}
+
+ public function isMounted() {
+ return $this->getFileInfo()->isMounted();
+ }
+
+ public function isShared() {
+ return $this->getFileInfo()->isShared();
+ }
+
+ public function getMimeType() {
+ return $this->getFileInfo()->getMimetype();
+ }
+
+ public function getMimePart() {
+ return $this->getFileInfo()->getMimePart();
+ }
+
+ public function getType() {
+ return $this->getFileInfo()->getType();
+ }
+
+ public function isEncrypted() {
+ return $this->getFileInfo()->isEncrypted();
+ }
}