Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/Kolab/DAV/Node.php b/lib/Kolab/DAV/Node.php
index c75ec8a..f907303 100644
--- a/lib/Kolab/DAV/Node.php
+++ b/lib/Kolab/DAV/Node.php
@@ -1,216 +1,215 @@
<?php
/**
* SabreDAV File Backend implementation for Kolab.
*
* @author Aleksander Machniak <machniak@kolabsys.com>
*
* Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Kolab\DAV;
use \Exception;
/**
* Node class
*/
class Node implements \Sabre\DAV\INode
{
/**
* The path to the current node
*
* @var string
*/
protected $path;
/**
* The file API backend class
*
* @var Kolab\DAV\Backend
*/
protected $backend;
/**
* Internal node data (e.g. file parameters)
*
* @var array
*/
protected $data;
/**
* Parent node
*
* @var Kolab\DAV\Node
*/
protected $parent;
/**
* @brief Sets up the node, expects a full path name
* @param string $path Node name with path
* @param Kolab\DAV\Node $parent Parent node
* @param array $data Node data
*
* @return void
*/
public function __construct($path, $parent = null, $data = array())
{
$this->data = $data;
$this->path = $path;
$this->parent = $parent;
$this->backend = Backend::get_instance();
if ($this->path == Collection::ROOT_DIRECTORY) {
$this->path = '';
}
else if (strpos($this->path, Collection::ROOT_DIRECTORY . '/') === 0) {
$this->path = substr($this->path, strlen(Collection::ROOT_DIRECTORY . '/'));
}
}
/**
* Returns the last modification time
*
* In this case, it will simply return the current time
*
* @return int
*/
public function getLastModified()
{
return !empty($this->data['modified']) ? $this->data['modified'] : null;
}
/**
* Deletes the current node (folder)
*
* @throws Sabre\DAV\Exception
* @return void
*/
public function delete()
{
try {
$this->backend->folder_delete($this->path);
}
catch (Exception $e) {
$this->throw_exception($e);
}
// reset cache
if ($this->parent) {
$this->parent->children = null;
}
}
/**
* Renames the node
*
* @throws Sabre\DAV\Exception
* @param string $name The new name
* @return void
*/
public function setName($name)
{
$path = explode('/', $this->path);
array_pop($path);
$newname = implode('/', $path) . '/' . $name;
$method = (is_a($this, 'Kolab\\DAV\\File') ? 'file' : 'folder') . '_move';
try {
$this->backend->$method($this->path, $newname);
}
catch (Exception $e) {
$this->throw_exception($e);
}
// reset cache
if ($this->parent) {
$this->parent->children = null;
}
}
/**
* @brief Returns the name of the node
* @return string
*/
public function getName()
{
if ($this->path === '') {
return Collection::ROOT_DIRECTORY;
}
return array_pop(explode('/', $this->path));
}
/**
* Build file data array to pass into backend
*/
protected function fileData($name, $data = null)
{
if ($this->data && !empty($this->data['type'])) {
$type = $this->data['type'];
}
else {
$type = 'application/octet-stream';
}
// $data can be a resource or a string
if (is_resource($data)) {
- // $data can be php://input or php://temp
- // php://input is not seekable, we need to "convert"
- // it to seekable resource, fstat/rewind later will work
+ // It can be php://input or php://temp resource stream.
+ // php://input is seekable on recent PHP versions, but fstat() fails so we can't use it
$meta = stream_get_meta_data($data);
- if (!$meta['seekable']) {
+ if (empty($meta['seekable']) || fstat($data) === false) {
$new_data = fopen('php://temp','r+');
stream_copy_to_stream($data, $new_data);
rewind($new_data);
$data = $new_data;
}
else {
rewind($data);
}
}
$filedata = array(
'content' => $data,
'type' => $type,
);
return $filedata;
}
/**
* Convert Chwala exceptions to Sabre exceptions
*
* @param Exception Chwala exception
* @throws Sabre\DAV\Exception
*/
protected function throw_exception($e)
{
$error = $e->getCode();
$msg = $e->getMessage();
if ($error == \file_storage::ERROR_UNAVAILABLE) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($msg);
}
else if ($error == \file_storage::ERROR_FORBIDDEN) {
throw new \Sabre\DAV\Exception\Forbidden($msg);
}
throw new \Sabre\DAV\Exception($msg);
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Apr 4, 12:33 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18821415
Default Alt Text
(5 KB)

Event Timeline