/** * get a watcher instance for the cache * * @param string $path * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher * @return \OC\Files\Cache\Watcher */ public function getWatcher($path = '', $storage = null) { if (!$storage) { $storage = $this; } return $this->storage->getWatcher($path, $storage); }
/** * 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); }
/** * Get file info from cache * * If the file is not in cached it will be scanned * If the file has changed on storage the cache will be updated * * @param \OC\Files\Storage\Storage $storage * @param string $internalPath * @param string $relativePath * @return array|bool */ private function getCacheEntry($storage, $internalPath, $relativePath) { $cache = $storage->getCache($internalPath); $data = $cache->get($internalPath); $watcher = $storage->getWatcher($internalPath); try { // if the file is not in the cache or needs to be updated, trigger the scanner and reload the data if (!$data || $data['size'] === -1) { $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED); if (!$storage->file_exists($internalPath)) { $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); return false; } $scanner = $storage->getScanner($internalPath); $scanner->scan($internalPath, Cache\Scanner::SCAN_SHALLOW); $data = $cache->get($internalPath); $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); } else { if (!Cache\Scanner::isPartialFile($internalPath) && $watcher->needsUpdate($internalPath, $data)) { $this->lockFile($relativePath, ILockingProvider::LOCK_SHARED); $watcher->update($internalPath, $data); $storage->getPropagator()->propagateChange($internalPath, time()); $data = $cache->get($internalPath); $this->unlockFile($relativePath, ILockingProvider::LOCK_SHARED); } } } catch (LockedException $e) { // if the file is locked we just use the old cache info } return $data; }
/** * get a watcher instance for the cache * * @param string $path * @return \OC\Files\Cache\Watcher */ public function getWatcher($path = '') { return $this->storage->getWatcher($path); }