protected function setUp() { parent::setUp(); $this->storage = new \OC\Files\Storage\Temporary(array()); $textData = "dummy file data\n"; $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); $this->storage->mkdir('folder'); $this->storage->file_put_contents('foo.txt', $textData); $this->storage->file_put_contents('foo.png', $imgData); $this->storage->file_put_contents('folder/bar.txt', $textData); $this->storage->file_put_contents('folder/bar2.txt', $textData); $this->scanner = $this->storage->getScanner(); $this->scanner->scan(''); $this->cache = $this->storage->getCache(); if (!self::$user) { self::$user = $this->getUniqueID(); } \OC_User::createUser(self::$user, 'password'); $this->loginAsUser(self::$user); Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); \OC_Hook::clear('OC_Filesystem'); }
public function setUp() { // remember files_encryption state $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption'); // we want to tests with the encryption app disabled \OC_App::disable('files_encryption'); $this->storage = new \OC\Files\Storage\Temporary(array()); $textData = "dummy file data\n"; $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png'); $this->storage->mkdir('folder'); $this->storage->file_put_contents('foo.txt', $textData); $this->storage->file_put_contents('foo.png', $imgData); $this->storage->file_put_contents('folder/bar.txt', $textData); $this->storage->file_put_contents('folder/bar2.txt', $textData); $this->scanner = $this->storage->getScanner(); $this->scanner->scan(''); $this->cache = $this->storage->getCache(); \OC\Files\Filesystem::tearDown(); if (!self::$user) { self::$user = uniqid(); } \OC_User::createUser(self::$user, 'password'); \OC_User::setUserId(self::$user); \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files'); Filesystem::clearMounts(); Filesystem::mount($this->storage, array(), '/' . self::$user . '/files'); \OC_Hook::clear('OC_Filesystem'); }
function testBackgroundScan() { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); $this->assertEquals([], $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW), 'Asserting that no error occurred while scan(SCAN_SHALLOW)'); $this->scanner->backgroundScan(); $this->assertTrue(true, 'Asserting that no error occurred while backgroundScan()'); }
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 $this->view->rename('/foo', '/bar/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 testMoveDisabled() { $this->storage->file_put_contents('foo.txt', 'qwerty'); $this->updater->update('foo.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $cached = $this->cache->get('foo.txt'); $this->storage->rename('foo.txt', 'bar.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $this->updater->disable(); $this->updater->rename('foo.txt', 'bar.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); }
function testBackgroundScan() { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW); $this->assertFalse($this->cache->inCache('folder/bar.txt')); $this->assertFalse($this->cache->inCache('folder/2bar.txt')); $cachedData = $this->cache->get(''); $this->assertEquals(-1, $cachedData['size']); $this->scanner->backgroundScan(); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $cachedData = $this->cache->get(''); $this->assertnotEquals(-1, $cachedData['size']); $this->assertFalse($this->cache->getIncomplete()); }
public function testMove() { $this->storage->file_put_contents('foo.txt', 'qwerty'); $this->updater->update('foo.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $cached = $this->cache->get('foo.txt'); $this->storage->rename('foo.txt', 'bar.txt'); $this->assertTrue($this->cache->inCache('foo.txt')); $this->assertFalse($this->cache->inCache('bar.txt')); $this->updater->rename('foo.txt', 'bar.txt'); $this->assertFalse($this->cache->inCache('foo.txt')); $this->assertTrue($this->cache->inCache('bar.txt')); $cachedTarget = $this->cache->get('bar.txt'); $this->assertEquals($cached['etag'], $cachedTarget['etag']); $this->assertEquals($cached['mtime'], $cachedTarget['mtime']); $this->assertEquals($cached['size'], $cachedTarget['size']); $this->assertEquals($cached['fileid'], $cachedTarget['fileid']); }
function testBackgroundScanOnlyRecurseIncomplete() { $this->fillTestFolders(); $this->storage->mkdir('folder2'); $this->storage->file_put_contents('folder2/bar.txt', 'foobar'); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW); $this->assertFalse($this->cache->inCache('folder/bar.txt')); $this->assertFalse($this->cache->inCache('folder/2bar.txt')); $this->assertFalse($this->cache->inCache('folder2/bar.txt')); $this->cache->put('folder2', ['size' => 1]); // mark as complete $cachedData = $this->cache->get(''); $this->assertEquals(-1, $cachedData['size']); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE_INCOMPLETE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $this->assertTrue($this->cache->inCache('folder/bar.txt')); $this->assertFalse($this->cache->inCache('folder2/bar.txt')); $cachedData = $this->cache->get(''); $this->assertNotEquals(-1, $cachedData['size']); $this->assertFalse($this->cache->getIncomplete()); }
/** * Tests that writing a file using the shared storage will propagate the file * size to the owner's parent folders. */ function testSubFolderSizePropagationToOwnerStorage() { $initialSizes = self::getOwnerDirSizes('files/container/shareddir/subdir'); $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $dataLen = strlen($textData); $this->sharedCache->put('subdir/bar.txt', array('mtime' => 10, 'storage_mtime' => 10, 'size' => $dataLen, 'mimetype' => 'text/plain')); $this->sharedStorage->file_put_contents('subdir/bar.txt', $textData); $this->sharedCache->put('subdir', array('mtime' => 10, 'storage_mtime' => 10, 'size' => $dataLen, 'mimetype' => 'text/plain')); // run the propagation code $result = $this->sharedStorage->getWatcher()->checkUpdate('subdir'); $this->assertTrue($result); // the owner's parent dirs must have increase size $newSizes = self::getOwnerDirSizes('files/container/shareddir/subdir'); $this->assertEquals($initialSizes[''] + $dataLen, $newSizes['']); $this->assertEquals($initialSizes['files'] + $dataLen, $newSizes['files']); $this->assertEquals($initialSizes['files/container'] + $dataLen, $newSizes['files/container']); $this->assertEquals($initialSizes['files/container/shareddir'] + $dataLen, $newSizes['files/container/shareddir']); $this->assertEquals($initialSizes['files/container/shareddir/subdir'] + $dataLen, $newSizes['files/container/shareddir/subdir']); // no more updates $result = $this->sharedStorage->getWatcher()->checkUpdate('subdir'); $this->assertFalse($result); }
/** * see http://php.net/manual/en/function.file_put_contents.php * * @param string $path * @param string $data * @return bool */ public function file_put_contents($path, $data) { return $this->storage->file_put_contents($path, $data); }