if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
$this->sendHooks(array('preWrite'));
$this->view->file_put_contents($this->path, $data);
+ $this->fileInfo = null;
$this->sendHooks(array('postWrite'));
} else {
throw new NotPermittedException();
}
}
- /**
- * @return string
- */
- public function getMimeType() {
- return $this->view->getMimeType($this->path);
- }
-
/**
* @param string $mode
* @return resource
$nonExisting = new NonExistingFile($this->root, $this->view, $this->path);
$this->root->emit('\OC\Files', 'postDelete', array($nonExisting));
$this->exists = false;
+ $this->fileInfo = null;
} else {
throw new NotPermittedException();
}
$this->root->emit('\OC\Files', 'postRename', array($this, $targetNode));
$this->root->emit('\OC\Files', 'postWrite', array($targetNode));
$this->path = $targetPath;
+ $this->fileInfo = null;
return $targetNode;
} else {
throw new NotPermittedException();
return $this->view->free_space($this->path);
}
- /**
- * @return bool
- */
- public function isCreatable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
- }
-
public function delete() {
if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
$this->sendHooks(array('preDelete'));
namespace OC\Files\Node;
-use OCP\Files\NotFoundException;
+use OCP\Files\FileInfo;
use OCP\Files\NotPermittedException;
-class Node implements \OCP\Files\Node {
+class Node implements \OCP\Files\Node, FileInfo {
/**
* @var \OC\Files\View $view
*/
*/
protected $path;
+ /**
+ * @var \OCP\Files\FileInfo
+ */
+ protected $fileInfo;
+
/**
* @param \OC\Files\View $view
* @param \OC\Files\Node\Root $root
$this->path = $path;
}
+ private function getFileInfo() {
+ if (!$this->fileInfo) {
+ $this->fileInfo = $this->view->getFileInfo($this->path);
+ }
+ return $this->fileInfo;
+ }
+
/**
* @param string[] $hooks
*/
$this->sendHooks(array('preTouch'));
$this->view->touch($this->path, $mtime);
$this->sendHooks(array('postTouch'));
+ if ($this->fileInfo) {
+ if (is_null($mtime)) {
+ $mtime = time();
+ }
+ $this->fileInfo['mtime'] = $mtime;
+ }
} else {
throw new NotPermittedException();
}
* @return int
*/
public function getId() {
- $info = $this->view->getFileInfo($this->path);
- return $info['fileid'];
+ return $this->getFileInfo()->getId();
}
/**
* @return int
*/
public function getMTime() {
- return $this->view->filemtime($this->path);
+ return $this->getFileInfo()->getMTime();
}
/**
* @return int
*/
public function getSize() {
- return $this->view->filesize($this->path);
+ return $this->getFileInfo()->getSize();
}
/**
* @return string
*/
public function getEtag() {
- $info = $this->view->getFileInfo($this->path);
- return $info['etag'];
+ return $this->getFileInfo()->getEtag();
}
/**
* @return int
*/
public function getPermissions() {
- $info = $this->view->getFileInfo($this->path);
- return $info['permissions'];
+ return $this->getFileInfo()->getPermissions();
}
/**
* @return bool
*/
public function isReadable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
+ return $this->getFileInfo()->isReadable();
}
/**
* @return bool
*/
public function isUpdateable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
+ return $this->getFileInfo()->isUpdateable();
}
/**
* @return bool
*/
public function isDeletable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
+ return $this->getFileInfo()->isDeletable();
}
/**
* @return bool
*/
public function isShareable() {
- return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
+ return $this->getFileInfo()->isShareable();
+ }
+
+ public function isCreatable() {
+ return $this->getFileInfo()->isCreatable();
}
/**
}
return true;
}
+
+ public function isMounted() {
+ return $this->getFileInfo()->isMounted();
+ }
+
+ public function isShared() {
+ return $this->getFileInfo()->isShared();
+ }
+
+ public function getMimeType() {
+ return $this->getFileInfo()->getMimetype();
+ }
+
+ public function getMimePart() {
+ return $this->getFileInfo()->getMimePart();
+ }
+
+ public function getType() {
+ return $this->getFileInfo()->getType();
+ }
+
+ public function isEncrypted() {
+ return $this->getFileInfo()->isEncrypted();
+ }
}
namespace Test\Files\Node;
+use OC\Files\FileInfo;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OC\Files\View;
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testDelete() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('unlink')
$view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
$view->expects($this->once())
->method('unlink')
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->delete();
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals('bar', $node->getContent());
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => 0)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => 0))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->getContent();
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('file_put_contents')
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->putContent('bar');
$root = $this->getMock('\OC\Files\Node\Root', array(), array($manager, $view, $this->user));
$view->expects($this->once())
- ->method('getMimeType')
+ ->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue('text/plain'));
+ ->will($this->returnValue($this->getFileInfo(array('mimetype' => 'text/plain'))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals('text/plain', $node->getMimeType());
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$fh = $node->fopen('r');
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$fh = $node->fopen('w');
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => 0)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => 0))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->fopen('r');
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_UPDATE)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_UPDATE))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->fopen('w');
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$node->fopen('w');
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 3))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ, 'fileid' => 3))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$parentNode = new \OC\Files\Node\Folder($root, $view, '/bar');
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$view->expects($this->never())
->method('rename');
namespace Test\Files\Node;
use OC\Files\Cache\Cache;
+use OC\Files\FileInfo;
use OC\Files\Mount\Mount;
use OC\Files\Node\Node;
use OCP\Files\NotFoundException;
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testDelete() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
/**
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('rmdir')
$view->expects($this->any())
->method('getFileInfo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL, 'fileid' => 1))));
$view->expects($this->once())
->method('rmdir')
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$node->delete();
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('mkdir')
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$node->newFolder('asd');
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$view->expects($this->once())
->method('touch')
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
$node->newFile('asd');
namespace Test\Files\Node;
+use OC\Files\FileInfo;
+
class Node extends \Test\TestCase {
private $user;
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testStat() {
$manager = $this->getMock('\OC\Files\Mount\Manager');
/**
->method('getUser')
->will($this->returnValue($this->user));
- $stat = array(
+ $stat = $this->getFileInfo(array(
'fileid' => 1,
'size' => 100,
'etag' => 'qwerty',
'mtime' => 50
- );
+ ));
$view->expects($this->once())
->method('getFileInfo')
->method('getUser')
->will($this->returnValue($this->user));
+
+ $stat = $this->getFileInfo(array(
+ 'fileid' => 1,
+ 'size' => 100,
+ 'etag' => 'qwerty',
+ 'mtime' => 50
+ ));
+
$view->expects($this->once())
- ->method('filesize')
+ ->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(100));
+ ->will($this->returnValue($stat));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals(100, $node->getSize());
->method('getUser')
->will($this->returnValue($this->user));
- $stat = array(
+ $stat = $this->getFileInfo(array(
'fileid' => 1,
'size' => 100,
'etag' => 'qwerty',
'mtime' => 50
- );
+ ));
$view->expects($this->once())
->method('getFileInfo')
$root->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
- /**
- * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage
- */
- $storage = $this->getMock('\OC\Files\Storage\Storage');
+
+ $stat = $this->getFileInfo(array(
+ 'fileid' => 1,
+ 'size' => 100,
+ 'etag' => 'qwerty',
+ 'mtime' => 50
+ ));
$view->expects($this->once())
- ->method('filemtime')
+ ->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(50));
+ ->will($this->returnValue($stat));
$node = new \OC\Files\Node\File($root, $view, '/bar/foo');
$this->assertEquals(50, $node->getMTime());
->with('/bar/foo', 100)
->will($this->returnValue(true));
- $view->expects($this->once())
- ->method('filemtime')
- ->with('/bar/foo')
- ->will($this->returnValue(100));
-
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
$view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_ALL)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_ALL))));
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
$view->expects($this->any())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('permissions' => \OCP\Constants::PERMISSION_READ)));
+ ->will($this->returnValue($this->getFileInfo(array('permissions' => \OCP\Constants::PERMISSION_READ))));
$node = new \OC\Files\Node\Node($root, $view, '/bar/foo');
$node->touch(100);
namespace Test\Files\Node;
+use OC\Files\FileInfo;
use OCP\Files\NotPermittedException;
use OC\Files\Mount\Manager;
$this->user = new \OC\User\User('', new \OC_User_Dummy);
}
+ protected function getFileInfo($data) {
+ return new FileInfo('', null, '', $data);
+ }
+
public function testGet() {
$manager = new Manager();
/**
$view->expects($this->once())
->method('getFileInfo')
->with('/bar/foo')
- ->will($this->returnValue(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain')));
+ ->will($this->returnValue($this->getFileInfo(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain'))));
$view->expects($this->once())
->method('is_dir')