Add metadata to post delete hooks

This commit is contained in:
Robin Appelman 2015-12-01 13:22:58 +01:00
parent 36660734a6
commit 0d63e95a5d
6 changed files with 108 additions and 23 deletions

View File

@ -99,8 +99,9 @@ class File extends Node implements \OCP\Files\File {
public function delete() { public function delete() {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
$this->sendHooks(array('preDelete')); $this->sendHooks(array('preDelete'));
$fileInfo = $this->getFileInfo();
$this->view->unlink($this->path); $this->view->unlink($this->path);
$nonExisting = new NonExistingFile($this->root, $this->view, $this->path); $nonExisting = new NonExistingFile($this->root, $this->view, $this->path, $fileInfo);
$this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); $this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
$this->exists = false; $this->exists = false;
$this->fileInfo = null; $this->fileInfo = null;

View File

@ -295,8 +295,9 @@ class Folder extends Node implements \OCP\Files\Folder {
public function delete() { public function delete() {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
$this->sendHooks(array('preDelete')); $this->sendHooks(array('preDelete'));
$fileInfo = $this->getFileInfo();
$this->view->rmdir($this->path); $this->view->rmdir($this->path);
$nonExisting = new NonExistingFolder($this->root, $this->view, $this->path); $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo);
$this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); $this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
$this->exists = false; $this->exists = false;
} else { } else {

View File

@ -46,44 +46,80 @@ class NonExistingFile extends File {
} }
public function getId() { public function getId() {
if ($this->fileInfo) {
return parent::getId();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function stat() { public function stat() {
throw new NotFoundException(); throw new NotFoundException();
} }
public function getMTime() { public function getMTime() {
if ($this->fileInfo) {
return parent::getMTime();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getSize() { public function getSize() {
if ($this->fileInfo) {
return parent::getSize();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getEtag() { public function getEtag() {
if ($this->fileInfo) {
return parent::getEtag();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getPermissions() { public function getPermissions() {
if ($this->fileInfo) {
return parent::getPermissions();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isReadable() { public function isReadable() {
if ($this->fileInfo) {
return parent::isReadable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isUpdateable() { public function isUpdateable() {
if ($this->fileInfo) {
return parent::isUpdateable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isDeletable() { public function isDeletable() {
if ($this->fileInfo) {
return parent::isDeletable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isShareable() { public function isShareable() {
if ($this->fileInfo) {
return parent::isShareable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getContent() { public function getContent() {
throw new NotFoundException(); throw new NotFoundException();
@ -94,8 +130,12 @@ class NonExistingFile extends File {
} }
public function getMimeType() { public function getMimeType() {
if ($this->fileInfo) {
return parent::getMimeType();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function fopen($mode) { public function fopen($mode) {
throw new NotFoundException(); throw new NotFoundException();

View File

@ -47,44 +47,80 @@ class NonExistingFolder extends Folder {
} }
public function getId() { public function getId() {
if ($this->fileInfo) {
return parent::getId();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function stat() { public function stat() {
throw new NotFoundException(); throw new NotFoundException();
} }
public function getMTime() { public function getMTime() {
if ($this->fileInfo) {
return parent::getMTime();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getSize() { public function getSize() {
if ($this->fileInfo) {
return parent::getSize();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getEtag() { public function getEtag() {
if ($this->fileInfo) {
return parent::getEtag();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function getPermissions() { public function getPermissions() {
if ($this->fileInfo) {
return parent::getPermissions();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isReadable() { public function isReadable() {
if ($this->fileInfo) {
return parent::isReadable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isUpdateable() { public function isUpdateable() {
if ($this->fileInfo) {
return parent::isUpdateable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isDeletable() { public function isDeletable() {
if ($this->fileInfo) {
return parent::isDeletable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function isShareable() { public function isShareable() {
if ($this->fileInfo) {
return parent::isShareable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
}
public function get($path) { public function get($path) {
throw new NotFoundException(); throw new NotFoundException();
@ -127,6 +163,10 @@ class NonExistingFolder extends Folder {
} }
public function isCreatable() { public function isCreatable() {
if ($this->fileInfo) {
return parent::isCreatable();
} else {
throw new NotFoundException(); throw new NotFoundException();
} }
} }
}

View File

@ -76,6 +76,8 @@ class File extends \Test\TestCase {
$test->assertInstanceOf('\OC\Files\Node\NonExistingFile', $node); $test->assertInstanceOf('\OC\Files\Node\NonExistingFile', $node);
$test->assertEquals('foo', $node->getInternalPath()); $test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath()); $test->assertEquals('/bar/foo', $node->getPath());
$test->assertEquals(1, $node->getId());
$test->assertEquals('text/plain', $node->getMimeType());
$hooksRun++; $hooksRun++;
}; };
@ -94,7 +96,7 @@ class File extends \Test\TestCase {
$view->expects($this->any()) $view->expects($this->any())
->method('getFileInfo') ->method('getFileInfo')
->with('/bar/foo') ->with('/bar/foo')
->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)))); ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1, 'mimetype' => 'text/plain'))));
$view->expects($this->once()) $view->expects($this->once())
->method('unlink') ->method('unlink')

View File

@ -82,6 +82,7 @@ class Folder extends \Test\TestCase {
$test->assertInstanceOf('\OC\Files\Node\NonExistingFolder', $node); $test->assertInstanceOf('\OC\Files\Node\NonExistingFolder', $node);
$test->assertEquals('foo', $node->getInternalPath()); $test->assertEquals('foo', $node->getInternalPath());
$test->assertEquals('/bar/foo', $node->getPath()); $test->assertEquals('/bar/foo', $node->getPath());
$test->assertEquals(1, $node->getId());
$hooksRun++; $hooksRun++;
}; };