diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-02-12 12:29:01 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-23 22:27:23 +0100 |
commit | 9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f (patch) | |
tree | fa72017a9bf76c526ddb3dfe0969f0584a4a7d67 /lib/private/connector/sabre/node.php | |
parent | 66e3211fd8a57b0fb296d1dcc980272721e9f99d (diff) | |
download | nextcloud-server-9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f.tar.gz nextcloud-server-9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f.zip |
Sabre Update to 2.1
- VObject fixes for Sabre\VObject 3.3
- Remove VObject property workarounds
- Added prefetching for tags in sabre tags plugin
- Moved oc_properties logic to separate PropertyStorage backend (WIP)
- Fixed Sabre connector namespaces
- Improved files plugin to handle props on-demand
- Moved allowed props from server class to files plugin
- Fixed tags caching for files that are known to have no tags
(less queries)
- Added/fixed unit tests for Sabre FilesPlugin, TagsPlugin
- Replace OC\Connector\Sabre\Request with direct call to
httpRequest->setUrl()
- Fix exception detection in DAV client when using Sabre\DAV\Client
- Added setETag() on Node instead of using the static FileSystem
- Also preload tags/props when depth is infinity
Diffstat (limited to 'lib/private/connector/sabre/node.php')
-rw-r--r-- | lib/private/connector/sabre/node.php | 156 |
1 files changed, 38 insertions, 118 deletions
diff --git a/lib/private/connector/sabre/node.php b/lib/private/connector/sabre/node.php index 7df4453cb25..8fee6a4eb4e 100644 --- a/lib/private/connector/sabre/node.php +++ b/lib/private/connector/sabre/node.php @@ -1,36 +1,4 @@ <?php -/** - * @author Arthur Schiwon <blizzz@owncloud.com> - * @author Bart Visscher <bartv@thisnet.nl> - * @author Björn Schießle <schiessle@owncloud.com> - * @author Jakob Sack <mail@jakobsack.de> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Klaas Freitag <freitag@owncloud.com> - * @author Markus Goetz <markus@woboq.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <icewind@owncloud.com> - * @author Sam Tuke <mail@samtuke.com> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2015, 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/> - * - */ -use Sabre\DAV\URLUtil; -use OC\Connector\Sabre\TagList; /** * ownCloud @@ -52,10 +20,10 @@ use OC\Connector\Sabre\TagList; * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ -abstract class OC_Connector_Sabre_Node implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { - const GETETAG_PROPERTYNAME = '{DAV:}getetag'; - const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; +namespace OC\Connector\Sabre; + +abstract class Node implements \Sabre\DAV\INode { /** * Allow configuring the method used to generate Etags * @@ -111,6 +79,15 @@ abstract class OC_Connector_Sabre_Node implements \Sabre\DAV\INode, \Sabre\DAV\I } /** + * Returns the full path + * + * @return string + */ + public function getPath() { + return $this->path; + } + + /** * Renames the node * @param string $name The new name * @throws \Sabre\DAV\Exception\BadRequest @@ -123,23 +100,19 @@ abstract class OC_Connector_Sabre_Node implements \Sabre\DAV\INode, \Sabre\DAV\I throw new \Sabre\DAV\Exception\Forbidden(); } - list($parentPath,) = URLUtil::splitPath($this->path); - list(, $newName) = URLUtil::splitPath($name); + list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); + list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); if (!\OCP\Util::isValidFileName($newName)) { throw new \Sabre\DAV\Exception\BadRequest(); } $newPath = $parentPath . '/' . $newName; - $oldPath = $this->path; $this->fileView->rename($this->path, $newPath); $this->path = $newPath; - $query = OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertypath` = ?' - . ' WHERE `userid` = ? AND `propertypath` = ?'); - $query->execute(array($newPath, OC_User::getUser(), $oldPath)); $this->refreshInfo(); } @@ -170,91 +143,38 @@ abstract class OC_Connector_Sabre_Node implements \Sabre\DAV\INode, \Sabre\DAV\I } /** - * Updates properties on this node, - * @see \Sabre\DAV\IProperties::updateProperties - * @param array $properties - * @return boolean + * Returns the ETag for a file + * + * An ETag is a unique identifier representing the current version of the + * file. If the file changes, the ETag MUST change. The ETag is an + * arbitrary string, but MUST be surrounded by double-quotes. + * + * Return null if the ETag can not effectively be determined + * + * @return string */ - public function updateProperties($properties) { - $existing = $this->getProperties(array()); - foreach ($properties as $propertyName => $propertyValue) { - // If it was null, we need to delete the property - if (is_null($propertyValue)) { - if (array_key_exists($propertyName, $existing)) { - $query = OC_DB::prepare('DELETE FROM `*PREFIX*properties`' - . ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'); - $query->execute(array(OC_User::getUser(), $this->path, $propertyName)); - } - } else { - if (strcmp($propertyName, self::GETETAG_PROPERTYNAME) === 0) { - \OC\Files\Filesystem::putFileInfo($this->path, array('etag' => $propertyValue)); - } elseif (strcmp($propertyName, self::LASTMODIFIED_PROPERTYNAME) === 0) { - $this->touch($propertyValue); - } else { - if (!array_key_exists($propertyName, $existing)) { - $query = OC_DB::prepare('INSERT INTO `*PREFIX*properties`' - . ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'); - $query->execute(array(OC_User::getUser(), $this->path, $propertyName, $propertyValue)); - } else { - $query = OC_DB::prepare('UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' - . ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'); - $query->execute(array($propertyValue, OC_User::getUser(), $this->path, $propertyName)); - } - } - } - - } - $this->setPropertyCache(null); - return true; + public function getETag() { + return '"' . $this->info->getEtag() . '"'; } /** - * removes all properties for this node and user + * Sets the ETag + * + * @param string $etag + * + * @return int file id of updated file or -1 on failure */ - public function removeProperties() { - $query = OC_DB::prepare('DELETE FROM `*PREFIX*properties`' - . ' WHERE `userid` = ? AND `propertypath` = ?'); - $query->execute(array(OC_User::getUser(), $this->path)); - - $this->setPropertyCache(null); + public function setETag($etag) { + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); } /** - * Returns a list of properties for this nodes.; - * @param array $properties - * @return array - * @note The properties list is a list of propertynames the client - * requested, encoded as xmlnamespace#tagName, for example: - * http://www.example.org/namespace#author If the array is empty, all - * properties should be returned + * Returns the size of the node, in bytes + * + * @return int|float */ - public function getProperties($properties) { - - if (is_null($this->property_cache)) { - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; - $result = OC_DB::executeAudited($sql, array(OC_User::getUser(), $this->path)); - - $this->property_cache = array(); - while ($row = $result->fetchRow()) { - $this->property_cache[$row['propertyname']] = $row['propertyvalue']; - } - - $this->property_cache[self::GETETAG_PROPERTYNAME] = '"' . $this->info->getEtag() . '"'; - } - - // if the array was empty, we need to return everything - if (count($properties) == 0) { - return $this->property_cache; - } - - $props = array(); - foreach ($properties as $property) { - if (isset($this->property_cache[$property])) { - $props[$property] = $this->property_cache[$property]; - } - } - - return $props; + public function getSize() { + return $this->info->getSize(); } /** @@ -271,7 +191,7 @@ abstract class OC_Connector_Sabre_Node implements \Sabre\DAV\INode, \Sabre\DAV\I */ public function getFileId() { if ($this->info->getId()) { - $instanceId = OC_Util::getInstanceId(); + $instanceId = \OC_Util::getInstanceId(); $id = sprintf('%08d', $this->info->getId()); return $id . $instanceId; } |