Exemplo n.º 1
0
	function testShallow() {
		$this->fillTestFolders();

		$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
		$this->assertEquals($this->cache->inCache(''), true);
		$this->assertEquals($this->cache->inCache('foo.txt'), true);
		$this->assertEquals($this->cache->inCache('foo.png'), true);
		$this->assertEquals($this->cache->inCache('folder'), true);
		$this->assertEquals($this->cache->inCache('folder/bar.txt'), false);

		$cachedDataFolder = $this->cache->get('');
		$cachedDataFolder2 = $this->cache->get('folder');

		$this->assertEquals(-1, $cachedDataFolder['size']);
		$this->assertEquals(-1, $cachedDataFolder2['size']);

		$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);

		$cachedDataFolder2 = $this->cache->get('folder');

		$this->assertNotEquals($cachedDataFolder2['size'], -1);

		$this->cache->correctFolderSize('folder');

		$cachedDataFolder = $this->cache->get('');
		$this->assertNotEquals($cachedDataFolder['size'], -1);
	}
Exemplo n.º 2
0
 /**
  * Rename a file or folder in the cache and update the size, etag and mtime of the parent folders
  *
  * @param IStorage $sourceStorage
  * @param string $source
  * @param string $target
  */
 public function renameFromStorage(IStorage $sourceStorage, $source, $target)
 {
     if (!$this->enabled or Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) {
         return;
     }
     $time = time();
     $sourceCache = $sourceStorage->getCache();
     $sourceUpdater = $sourceStorage->getUpdater();
     $sourcePropagator = $sourceStorage->getPropagator();
     if ($sourceCache->inCache($source)) {
         if ($this->cache->inCache($target)) {
             $this->cache->remove($target);
         }
         if ($sourceStorage === $this->storage) {
             $this->cache->move($source, $target);
         } else {
             $this->cache->moveFromCache($sourceCache, $source, $target);
         }
     }
     if (pathinfo($source, PATHINFO_EXTENSION) !== pathinfo($target, PATHINFO_EXTENSION)) {
         // handle mime type change
         $mimeType = $this->storage->getMimeType($target);
         $fileId = $this->cache->getId($target);
         $this->cache->update($fileId, ['mimetype' => $mimeType]);
     }
     $sourceCache->correctFolderSize($source);
     $this->cache->correctFolderSize($target);
     if ($sourceUpdater instanceof Updater) {
         $sourceUpdater->correctParentStorageMtime($source);
     }
     $this->correctParentStorageMtime($target);
     $this->updateStorageMTimeOnly($target);
     $sourcePropagator->propagateChange($source, $time);
     $this->propagator->propagateChange($target, $time);
 }
Exemplo n.º 3
0
 /**
  * walk over any folders that are not fully scanned yet and scan them
  */
 public function backgroundScan()
 {
     $lastPath = null;
     while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
         $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
         $this->cache->correctFolderSize($path);
         $lastPath = $path;
     }
 }
Exemplo n.º 4
0
	/**
	 * walk over any folders that are not fully scanned yet and scan them
	 */
	public function backgroundScan() {
		$lastPath = null;
		while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
			$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
			\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
			if ($this->cacheActive) {
				$this->cache->correctFolderSize($path);
			}
			$lastPath = $path;
		}
	}
Exemplo n.º 5
0
 /**
  * Update the cache for changes to $path
  *
  * @param string $path
  * @param ICacheEntry $cachedData
  */
 public function update($path, $cachedData)
 {
     if ($this->storage->is_dir($path)) {
         $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
     } else {
         $this->scanner->scanFile($path);
     }
     if ($cachedData['mimetype'] === 'httpd/unix-directory') {
         $this->cleanFolder($path);
     }
     $this->cache->correctFolderSize($path);
 }
Exemplo n.º 6
0
 private function runBackgroundScanJob(callable $callback, $path)
 {
     try {
         $callback();
         \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
         if ($this->cacheActive && $this->cache instanceof Cache) {
             $this->cache->correctFolderSize($path);
         }
     } catch (\OCP\Files\StorageInvalidException $e) {
         // skip unavailable storages
     } catch (\OCP\Files\StorageNotAvailableException $e) {
         // skip unavailable storages
     } catch (\OCP\Files\ForbiddenException $e) {
         // skip forbidden storages
     } catch (\OCP\Lock\LockedException $e) {
         // skip unavailable storages
     }
 }
Exemplo n.º 7
0
 /**
  * walk over any folders that are not fully scanned yet and scan them
  */
 public function backgroundScan()
 {
     $lastPath = null;
     while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
         try {
             $this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
             \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
             if ($this->cacheActive) {
                 $this->cache->correctFolderSize($path);
             }
         } catch (\OCP\Files\StorageInvalidException $e) {
             // skip unavailable storages
         } catch (\OCP\Files\StorageNotAvailableException $e) {
             // skip unavailable storages
         } catch (\OCP\Lock\LockedException $e) {
             // skip unavailable storages
         }
         // FIXME: this won't proceed with the next item, needs revamping of getIncomplete()
         // to make this possible
         $lastPath = $path;
     }
 }
Exemplo n.º 8
0
 /**
  * update the folder size and the size of all parent folders
  *
  * @param string|boolean $path
  * @param array $data (optional) meta data of the folder
  */
 public function correctFolderSize($path, $data = null)
 {
     $this->cache->correctFolderSize($path, $data);
 }