private function checkEntries($entries) { foreach ($entries as $entry) { $data = $this->storage->getCache()->get($entry[0]); $this->assertEquals($entry[1], $data['mimetype']); } }
public function testDeleteGhostFolder() { $storage = new Temporary(array()); $scanner = $storage->getScanner(); $cache = $storage->getCache(); $storage->mkdir('foo'); $storage->file_put_contents('foo/foo.txt', 'bar'); \OC\Files\Filesystem::mount($storage, array(), '/test/'); $scanner->scan(''); $storage->rmdir('foo'); $this->assertTrue($cache->inCache('foo')); $this->assertTrue($cache->inCache('foo/foo.txt')); $view = new \OC\Files\View('/test'); $rootInfo = $view->getFileInfo(''); $this->assertEquals(3, $rootInfo->getSize()); $view->rmdir('foo'); $newInfo = $view->getFileInfo(''); $this->assertFalse($cache->inCache('foo')); $this->assertFalse($cache->inCache('foo/foo.txt')); $this->assertNotEquals($rootInfo->getEtag(), $newInfo->getEtag()); $this->assertEquals(0, $newInfo->getSize()); }
public function testRenameWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); $view = new View('/' . self::$user . '/files'); $this->assertTrue($cache2->inCache('foo.txt')); $folderCachedData = $view->getFileInfo('folder'); $substorageCachedData = $cache2->get(''); $fooCachedData = $cache2->get('foo.txt'); Filesystem::rename('folder/substorage/foo.txt', 'folder/substorage/bar.txt'); $this->assertFalse($cache2->inCache('foo.txt')); $this->assertTrue($cache2->inCache('bar.txt')); $cachedData = $cache2->get('bar.txt'); $this->assertEquals($fooCachedData['fileid'], $cachedData['fileid']); $mtime = $cachedData['mtime']; $cachedData = $cache2->get(''); $this->assertInternalType('string', $substorageCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']); // rename can cause mtime change - invalid assert // $this->assertEquals($mtime, $cachedData['mtime']); $cachedData = $view->getFileInfo('folder'); $this->assertInternalType('string', $folderCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']); // rename can cause mtime change - invalid assert // $this->assertEquals($mtime, $cachedData['mtime']); }
public function testChangePropagator() { /** * @var \OC\Files\Cache\ChangePropagator $propagator */ $propagator = $this->getMock('\\OC\\Files\\Cache\\ChangePropagator', array('propagateChanges'), array(), '', false); $storage = new Temporary(array()); $mount = new MountPoint($storage, '/foo'); Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $scanner = new TestScanner('', \OC::$server->getDatabaseConnection()); $originalPropagator = $scanner->getPropagator(); $scanner->setPropagator($propagator); $scanner->addMount($mount); $scanner->scan(''); $changes = $propagator->getChanges(); $parents = $propagator->getAllParents(); sort($changes); sort($parents); $this->assertEquals(array('/foo', '/foo/folder', '/foo/folder/bar.txt', '/foo/foo.txt'), $changes); $this->assertEquals(array('/', '/foo', '/foo/folder'), $parents); $cache->put('foo.txt', array('storage_mtime' => time() - 50)); $propagator = $this->getMock('\\OC\\Files\\Cache\\ChangePropagator', array('propagateChanges'), array(), '', false); $scanner->setPropagator($propagator); $storage->file_put_contents('foo.txt', 'asdasd'); $scanner->scan(''); $changes = $propagator->getChanges(); $parents = $propagator->getAllParents(); $this->assertEquals(array('/foo/foo.txt'), $changes); $this->assertEquals(array('/', '/foo'), $parents); $scanner->setPropagator($originalPropagator); $oldInfo = $cache->get(''); $cache->put('foo.txt', array('storage_mtime' => time() - 70)); $storage->file_put_contents('foo.txt', 'asdasd'); $scanner->scan(''); $newInfo = $cache->get(''); $this->assertNotEquals($oldInfo['etag'], $newInfo['etag']); }
public function testTouchWithMountPoints() { $storage2 = new \OC\Files\Storage\Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/' . self::$user . '/files/folder/substorage'); Filesystem::file_put_contents('folder/substorage/foo.txt', 'asd'); $this->assertTrue($cache2->inCache('foo.txt')); $folderCachedData = $this->cache->get('folder'); $substorageCachedData = $cache2->get(''); $fooCachedData = $cache2->get('foo.txt'); $cachedData = $cache2->get('foo.txt'); $time = 1371006070; $this->cache->put('folder', ['mtime' => $time - 100]); Filesystem::touch('folder/substorage/foo.txt', $time); $cachedData = $cache2->get('foo.txt'); $this->assertInternalType('string', $fooCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($fooCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); $cachedData = $cache2->get(''); $this->assertInternalType('string', $substorageCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($substorageCachedData['etag'], $cachedData['etag']); $cachedData = $this->cache->get('folder'); $this->assertInternalType('string', $folderCachedData['etag']); $this->assertInternalType('string', $cachedData['etag']); $this->assertNotSame($folderCachedData['etag'], $cachedData['etag']); $this->assertEquals($time, $cachedData['mtime']); }
public function testMoveFolderCrossStorage() { $storage2 = new Temporary(array()); $cache2 = $storage2->getCache(); Filesystem::mount($storage2, array(), '/bar'); $this->storage->mkdir('foo'); $this->storage->mkdir('foo/bar'); $this->storage->file_put_contents('foo/foo.txt', 'qwerty'); $this->storage->file_put_contents('foo/bar.txt', 'foo'); $this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop'); $this->storage->getScanner()->scan(''); $this->assertTrue($this->cache->inCache('foo')); $this->assertTrue($this->cache->inCache('foo/foo.txt')); $this->assertTrue($this->cache->inCache('foo/bar.txt')); $this->assertTrue($this->cache->inCache('foo/bar')); $this->assertTrue($this->cache->inCache('foo/bar/bar.txt')); $cached = []; $cached[] = $this->cache->get('foo'); $cached[] = $this->cache->get('foo/foo.txt'); $cached[] = $this->cache->get('foo/bar.txt'); $cached[] = $this->cache->get('foo/bar'); $cached[] = $this->cache->get('foo/bar/bar.txt'); // add extension to trigger the possible mimetype change $storage2->moveFromStorage($this->storage, 'foo', 'foo.b'); $storage2->getUpdater()->renameFromStorage($this->storage, 'foo', 'foo.b'); $this->assertFalse($this->cache->inCache('foo')); $this->assertFalse($this->cache->inCache('foo/foo.txt')); $this->assertFalse($this->cache->inCache('foo/bar.txt')); $this->assertFalse($this->cache->inCache('foo/bar')); $this->assertFalse($this->cache->inCache('foo/bar/bar.txt')); $this->assertTrue($cache2->inCache('foo.b')); $this->assertTrue($cache2->inCache('foo.b/foo.txt')); $this->assertTrue($cache2->inCache('foo.b/bar.txt')); $this->assertTrue($cache2->inCache('foo.b/bar')); $this->assertTrue($cache2->inCache('foo.b/bar/bar.txt')); $cachedTarget = []; $cachedTarget[] = $cache2->get('foo.b'); $cachedTarget[] = $cache2->get('foo.b/foo.txt'); $cachedTarget[] = $cache2->get('foo.b/bar.txt'); $cachedTarget[] = $cache2->get('foo.b/bar'); $cachedTarget[] = $cache2->get('foo.b/bar/bar.txt'); foreach ($cached as $i => $old) { $new = $cachedTarget[$i]; $this->assertEquals($old['mtime'], $new['mtime']); $this->assertEquals($old['size'], $new['size']); $this->assertEquals($old['etag'], $new['etag']); $this->assertEquals($old['fileid'], $new['fileid']); $this->assertEquals($old['mimetype'], $new['mimetype']); } }
public function testPropagateEtag() { $storage = new Temporary(array()); $mount = new MountPoint($storage, ''); Filesystem::getMountManager()->addMount($mount); $cache = $storage->getCache(); $storage->mkdir('folder'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $storage->touch('folder/bar.txt', time() - 200); $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $scanner->addMount($mount); $scanner->scan(''); $this->assertTrue($cache->inCache('folder/bar.txt')); $oldRoot = $cache->get(''); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $scanner->scan(''); $newRoot = $cache->get(''); $this->assertNotEquals($oldRoot->getEtag(), $newRoot->getEtag()); }
public function testScanSubMount() { $uid = $this->getUniqueID(); $this->userBackend->createUser($uid, 'test'); $mountProvider = $this->getMock('\\OCP\\Files\\Config\\IMountProvider'); $storage = new Temporary(array()); $mount = new MountPoint($storage, '/' . $uid . '/files/foo'); $mountProvider->expects($this->any())->method('getMountsForUser')->will($this->returnCallback(function (IUser $user, IStorageFactory $storageFactory) use($mount, $uid) { if ($user->getUID() === $uid) { return [$mount]; } else { return []; } })); \OC::$server->getMountProviderCollection()->registerProvider($mountProvider); $cache = $storage->getCache(); $storage->mkdir('folder'); $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->getLogger()); $this->assertFalse($cache->inCache('folder/bar.txt')); $scanner->scan('/' . $uid . '/files/foo'); $this->assertTrue($cache->inCache('folder/bar.txt')); }