aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Node/File.php
diff options
context:
space:
mode:
authorThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-25 08:27:57 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-04-25 08:27:57 +0200
commita4b1d9feee79218268abcb0c20ed16bec82c993c (patch)
treea7ed9416b98d2f1de2e2846336d93433b3b6e88d /lib/private/Files/Node/File.php
parentdab4633300149ff3c67f7c72920539a9a1f66aa3 (diff)
parentdedf392751e1b27163f9dd49b2a54f410727c823 (diff)
downloadnextcloud-server-a4b1d9feee79218268abcb0c20ed16bec82c993c.tar.gz
nextcloud-server-a4b1d9feee79218268abcb0c20ed16bec82c993c.zip
Merge pull request #24226 from owncloud/files_psr4
Move \OC\Files to PSR-4
Diffstat (limited to 'lib/private/Files/Node/File.php')
-rw-r--r--lib/private/Files/Node/File.php176
1 files changed, 176 insertions, 0 deletions
diff --git a/lib/private/Files/Node/File.php b/lib/private/Files/Node/File.php
new file mode 100644
index 00000000000..9e0014abb0b
--- /dev/null
+++ b/lib/private/Files/Node/File.php
@@ -0,0 +1,176 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Roeland Jago Douma <rullzer@owncloud.com>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Files\Node;
+
+use OCP\Files\NotPermittedException;
+
+class File extends Node implements \OCP\Files\File {
+ /**
+ * @return string
+ * @throws \OCP\Files\NotPermittedException
+ */
+ public function getContent() {
+ if ($this->checkPermissions(\OCP\Constants::PERMISSION_READ)) {
+ /**
+ * @var \OC\Files\Storage\Storage $storage;
+ */
+ return $this->view->file_get_contents($this->path);
+ } else {
+ throw new NotPermittedException();
+ }
+ }
+
+ /**
+ * @param string $data
+ * @throws \OCP\Files\NotPermittedException
+ */
+ public function putContent($data) {
+ 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();
+ }
+ }
+
+ /**
+ * @param string $mode
+ * @return resource
+ * @throws \OCP\Files\NotPermittedException
+ */
+ public function fopen($mode) {
+ $preHooks = array();
+ $postHooks = array();
+ $requiredPermissions = \OCP\Constants::PERMISSION_READ;
+ switch ($mode) {
+ case 'r+':
+ case 'rb+':
+ case 'w+':
+ case 'wb+':
+ case 'x+':
+ case 'xb+':
+ case 'a+':
+ case 'ab+':
+ case 'w':
+ case 'wb':
+ case 'x':
+ case 'xb':
+ case 'a':
+ case 'ab':
+ $preHooks[] = 'preWrite';
+ $postHooks[] = 'postWrite';
+ $requiredPermissions |= \OCP\Constants::PERMISSION_UPDATE;
+ break;
+ }
+
+ if ($this->checkPermissions($requiredPermissions)) {
+ $this->sendHooks($preHooks);
+ $result = $this->view->fopen($this->path, $mode);
+ $this->sendHooks($postHooks);
+ return $result;
+ } else {
+ throw new NotPermittedException();
+ }
+ }
+
+ public function delete() {
+ if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
+ $this->sendHooks(array('preDelete'));
+ $fileInfo = $this->getFileInfo();
+ $this->view->unlink($this->path);
+ $nonExisting = new NonExistingFile($this->root, $this->view, $this->path, $fileInfo);
+ $this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
+ $this->exists = false;
+ $this->fileInfo = null;
+ } else {
+ throw new NotPermittedException();
+ }
+ }
+
+ /**
+ * @param string $targetPath
+ * @throws \OCP\Files\NotPermittedException
+ * @return \OC\Files\Node\Node
+ */
+ public function copy($targetPath) {
+ $targetPath = $this->normalizePath($targetPath);
+ $parent = $this->root->get(dirname($targetPath));
+ if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
+ $nonExisting = new NonExistingFile($this->root, $this->view, $targetPath);
+ $this->root->emit('\OC\Files', 'preCopy', array($this, $nonExisting));
+ $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
+ $this->view->copy($this->path, $targetPath);
+ $targetNode = $this->root->get($targetPath);
+ $this->root->emit('\OC\Files', 'postCopy', array($this, $targetNode));
+ $this->root->emit('\OC\Files', 'postWrite', array($targetNode));
+ return $targetNode;
+ } else {
+ throw new NotPermittedException();
+ }
+ }
+
+ /**
+ * @param string $targetPath
+ * @throws \OCP\Files\NotPermittedException
+ * @return \OC\Files\Node\Node
+ */
+ public function move($targetPath) {
+ $targetPath = $this->normalizePath($targetPath);
+ $parent = $this->root->get(dirname($targetPath));
+ if ($parent instanceof Folder and $this->isValidPath($targetPath) and $parent->isCreatable()) {
+ $nonExisting = new NonExistingFile($this->root, $this->view, $targetPath);
+ $this->root->emit('\OC\Files', 'preRename', array($this, $nonExisting));
+ $this->root->emit('\OC\Files', 'preWrite', array($nonExisting));
+ $this->view->rename($this->path, $targetPath);
+ $targetNode = $this->root->get($targetPath);
+ $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();
+ }
+ }
+
+ /**
+ * @param string $type
+ * @param bool $raw
+ * @return string
+ */
+ public function hash($type, $raw = false) {
+ return $this->view->hash($type, $this->path, $raw);
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getChecksum() {
+ return $this->getFileInfo()->getChecksum();
+ }
+}