diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-02-25 16:23:09 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-02-25 16:23:09 +0100 |
commit | 3a21755963d8d9897a48ab58292345c0b710e239 (patch) | |
tree | f6b8fd3065a03f2c5627b4f0d89c4b51d69c5c42 /lib/private/connector/sabre/file.php | |
parent | 9b4af31bac977cb788a6f4a013d32ba0a21437f0 (diff) | |
download | nextcloud-server-3a21755963d8d9897a48ab58292345c0b710e239.tar.gz nextcloud-server-3a21755963d8d9897a48ab58292345c0b710e239.zip |
Pass the filesystem view as argument in the sabredav connectors and use the fileinfo object
Diffstat (limited to 'lib/private/connector/sabre/file.php')
-rw-r--r-- | lib/private/connector/sabre/file.php | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index ef6caaf22a7..cbecd90b7d6 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -45,11 +45,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return string|null */ public function put($data) { - - $fs = $this->getFS(); - - if ($fs->file_exists($this->path) && - !$fs->isUpdatable($this->path)) { + if ($this->info && $this->fileView->file_exists($this->path) && + !$this->info->isUpdateable()) { throw new \Sabre_DAV_Exception_Forbidden(); } @@ -79,10 +76,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } try { - $putOkay = $fs->file_put_contents($partpath, $data); + $putOkay = $this->fileView->file_put_contents($partpath, $data); if ($putOkay === false) { \OC_Log::write('webdav', '\OC\Files\Filesystem::file_put_contents() failed', \OC_Log::ERROR); - $fs->unlink($partpath); + $this->fileView->unlink($partpath); // because we have no clue about the cause we can only throw back a 500/Internal Server Error throw new Sabre_DAV_Exception('Could not write file contents'); } @@ -105,29 +102,30 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } // rename to correct path - $renameOkay = $fs->rename($partpath, $this->path); - $fileExists = $fs->file_exists($this->path); + $renameOkay = $this->fileView->rename($partpath, $this->path); + $fileExists = $this->fileView->file_exists($this->path); if ($renameOkay === false || $fileExists === false) { \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR); - $fs->unlink($partpath); + $this->fileView->unlink($partpath); throw new Sabre_DAV_Exception('Could not rename part file to final file'); } // allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { - if($fs->touch($this->path, $mtime)) { + if($this->fileView->touch($this->path, $mtime)) { header('X-OC-MTime: accepted'); } } + $this->refreshInfo(); - return $this->getETagPropertyForPath($this->path); + return '"' . $this->info->getEtag() . '"'; } /** * Returns the data * - * @return string + * @return string | resource */ public function get() { @@ -135,7 +133,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D if (\OC_Util::encryptedFiles()) { throw new \Sabre_DAV_Exception_ServiceUnavailable(); } else { - return \OC\Files\Filesystem::fopen($this->path, 'rb'); + return $this->fileView->fopen($this->path, 'rb'); } } @@ -147,16 +145,14 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @throws Sabre_DAV_Exception_Forbidden */ public function delete() { - $fs = $this->getFS(); - if ($this->path === 'Shared') { throw new \Sabre_DAV_Exception_Forbidden(); } - if (!$fs->isDeletable($this->path)) { + if (!$this->info->isDeletable()) { throw new \Sabre_DAV_Exception_Forbidden(); } - $fs->unlink($this->path); + $this->fileView->unlink($this->path); // remove properties $this->removeProperties(); @@ -169,12 +165,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return int */ public function getSize() { - $this->getFileinfoCache(); - if ($this->fileinfo_cache['size'] > -1) { - return $this->fileinfo_cache['size']; - } else { - return null; - } + return $this->info->getSize(); } /** @@ -189,11 +180,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return mixed */ public function getETag() { - $properties = $this->getProperties(array(self::GETETAG_PROPERTYNAME)); - if (isset($properties[self::GETETAG_PROPERTYNAME])) { - return $properties[self::GETETAG_PROPERTYNAME]; - } - return null; + return $this->info->getEtag(); } /** @@ -204,12 +191,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return mixed */ public function getContentType() { - if (isset($this->fileinfo_cache['mimetype'])) { - return $this->fileinfo_cache['mimetype']; - } - - return \OC\Files\Filesystem::getMimeType($this->path); - + return $this->info->getMimetype(); } /** @@ -245,15 +227,14 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D $chunk_handler->file_assemble($partFile); // here is the final atomic rename - $fs = $this->getFS(); $targetPath = $path . '/' . $info['name']; - $renameOkay = $fs->rename($partFile, $targetPath); - $fileExists = $fs->file_exists($targetPath); + $renameOkay = $this->fileView->rename($partFile, $targetPath); + $fileExists = $this->fileView->file_exists($targetPath); if ($renameOkay === false || $fileExists === false) { \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR); // only delete if an error occurred and the target file was already created if ($fileExists) { - $fs->unlink($targetPath); + $this->fileView->unlink($targetPath); } throw new Sabre_DAV_Exception('Could not rename part file assembled from chunks'); } @@ -261,12 +242,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D // allow sync clients to send the mtime along in a header $mtime = OC_Request::hasModificationTime(); if ($mtime !== false) { - if($fs->touch($targetPath, $mtime)) { + if($this->fileView->touch($targetPath, $mtime)) { header('X-OC-MTime: accepted'); } } - return OC_Connector_Sabre_Node::getETagPropertyForPath($targetPath); + $info = $this->fileView->getFileInfo($targetPath); + return $info->getEtag(); } return null; |