Merge pull request #14437 from owncloud/node-check-fileinfo

Check if we have a proper fileinfo
This commit is contained in:
Thomas Müller 2015-02-27 02:56:13 -08:00
commit 7fe07e93fe
2 changed files with 31 additions and 2 deletions

View File

@ -8,6 +8,10 @@
namespace OC\Files\Node;
use OC\Files\Filesystem;
use OCP\Files\FileInfo;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
class Node implements \OCP\Files\Node {
@ -45,11 +49,21 @@ class Node implements \OCP\Files\Node {
/**
* Returns the matching file info
*
* @return \OCP\Files\FileInfo
* @return FileInfo
* @throws InvalidPathException
* @throws NotFoundException
*/
public function getFileInfo() {
if (!Filesystem::isValidPath($this->path)) {
throw new InvalidPathException();
}
if (!$this->fileInfo) {
$this->fileInfo = $this->view->getFileInfo($this->path);
$fileInfo = $this->view->getFileInfo($this->path);
if ($fileInfo instanceof FileInfo) {
$this->fileInfo = $fileInfo;
} else {
throw new NotFoundException();
}
}
return $this->fileInfo;
}

View File

@ -340,4 +340,19 @@ class Node extends \Test\TestCase {
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
}
/**
* @expectedException \OCP\Files\InvalidPathException
*/
public function testInvalidPath() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view = $this->getMock('\OC\Files\View');
$root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
$node = new \OC\Files\Node\Node($root, $view, '/../foo');
$node->getFileInfo();
}
}