creating non static getETagPropertyForPath()

adding public $fileView to Node to allow unit testing
This commit is contained in:
Thomas Müller 2013-09-24 15:35:21 +02:00
parent 4e7f82ef04
commit 84a0e6930b
3 changed files with 28 additions and 16 deletions

View File

@ -205,13 +205,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* If the array is empty, all properties should be returned
*
* @param array $properties
* @return void
* @return array
*/
public function getProperties($properties) {
$props = parent::getProperties($properties);
if (in_array(self::GETETAG_PROPERTYNAME, $properties) && !isset($props[self::GETETAG_PROPERTYNAME])) {
$props[self::GETETAG_PROPERTYNAME]
= OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
$props[self::GETETAG_PROPERTYNAME] = $this->getETagPropertyForPath($this->path);
}
return $props;
}

View File

@ -45,9 +45,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
* @return string|null
*/
public function put($data) {
if (\OC\Files\Filesystem::file_exists($this->path) &&
!\OC\Files\Filesystem::isUpdatable($this->path)) {
$fs = $this->getFS();
if ($fs->file_exists($this->path) &&
!$fs->isUpdatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
@ -69,7 +69,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
if ($chunk_handler->isComplete()) {
$newPath = $this->path . '/' . $info['name'];
$chunk_handler->file_assemble($newPath);
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
return $this->getETagPropertyForPath($newPath);
}
return null;
@ -78,10 +78,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
// mark file as partial while uploading (ignored by the scanner)
$partpath = $this->path . '.part';
$putOkay = \OC\Files\Filesystem::file_put_contents($partpath, $data);
$putOkay = $fs->file_put_contents($partpath, $data);
if ($putOkay === false) {
\OC_Log::write('webdav', '\OC\Files\Filesystem::file_put_contents() failed', \OC_Log::ERROR);
\OC\Files\Filesystem::unlink($partpath);
$fs->unlink($partpath);
throw new Sabre_DAV_Exception();
}
@ -89,9 +89,9 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
$actual = \OC\Files\Filesystem::filesize($partpath);
$actual = $fs->filesize($partpath);
if ($actual != $expected) {
\OC\Files\Filesystem::unlink($partpath);
$fs->unlink($partpath);
throw new Sabre_DAV_Exception_BadRequest(
'expected filesize ' . $expected . ' got ' . $actual);
}
@ -99,17 +99,17 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
}
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $this->path);
$fs->rename($partpath, $this->path);
// allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
if(\OC\Files\Filesystem::touch($this->path, $mtime)) {
if($fs->touch($this->path, $mtime)) {
header('X-OC-MTime: accepted');
}
}
return OC_Connector_Sabre_Node::getETagPropertyForPath($this->path);
return $this->getETagPropertyForPath($this->path);
}
/**

View File

@ -32,6 +32,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
*/
public static $ETagFunction = null;
/**
* is kept public to allow overwrite for unit testing
*
* @var \OC\Files\View
*/
public $fileView;
/**
* The path to the current node
*
@ -216,12 +223,18 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
* @param string $path Path of the file
* @return string|null Returns null if the ETag can not effectively be determined
*/
static public function getETagPropertyForPath($path) {
$data = \OC\Files\Filesystem::getFileInfo($path);
protected function getETagPropertyForPath($path) {
$data = $this->getFS()->getFileInfo($path);
if (isset($data['etag'])) {
return '"'.$data['etag'].'"';
}
return null;
}
protected function getFS() {
if (is_null($this->fileView)) {
$this->fileView = \OC\Files\Filesystem::getView();
}
return $this->fileView;
}
}