/**
  * Propagate the etag changes for all shares marked as dirty and mark the shares as clean
  *
  * @param array $shares the shares for the users
  * @param int $time
  */
 public function propagateDirtyMountPoints(array $shares, $time = null)
 {
     if ($time === null) {
         $time = microtime(true);
     }
     $dirtyShares = $this->getDirtyShares($shares);
     foreach ($dirtyShares as $share) {
         $this->changePropagator->addChange($share['file_target']);
     }
     if (count($dirtyShares)) {
         $this->config->setUserValue($this->userId, 'files_sharing', 'last_propagate', $time);
         $this->changePropagator->propagateChanges(floor($time));
     }
 }
 public function testPropagateCrossStorage()
 {
     $storage = new Temporary();
     $this->view->mkdir('/foo');
     Filesystem::mount($storage, [], $this->view->getAbsolutePath('/foo/submount'));
     $this->view->mkdir('/foo/submount/bar');
     $this->view->file_put_contents('/foo/submount/bar/sad.txt', 'qwerty');
     $oldInfo1 = $this->view->getFileInfo('/');
     $oldInfo2 = $this->view->getFileInfo('/foo');
     $oldInfo3 = $this->view->getFileInfo('/foo/submount');
     $oldInfo4 = $this->view->getFileInfo('/foo/submount/bar');
     $time = time() + 50;
     $this->propagator->addChange('/foo/submount/bar/sad.txt');
     $this->propagator->propagateChanges($time);
     $newInfo1 = $this->view->getFileInfo('/');
     $newInfo2 = $this->view->getFileInfo('/foo');
     $newInfo3 = $this->view->getFileInfo('/foo/submount');
     $newInfo4 = $this->view->getFileInfo('/foo/submount/bar');
     $this->assertEquals($newInfo1->getMTime(), $time);
     $this->assertEquals($newInfo2->getMTime(), $time);
     $this->assertEquals($newInfo3->getMTime(), $time);
     $this->assertEquals($newInfo4->getMTime(), $time);
     $this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag());
     $this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag());
     $this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag());
     $this->assertNotSame($oldInfo4->getEtag(), $newInfo3->getEtag());
 }
 public function testSinglePropagate()
 {
     $this->view->mkdir('/foo');
     $this->view->mkdir('/foo/bar');
     $this->view->file_put_contents('/foo/bar/sad.txt', 'qwerty');
     $oldInfo1 = $this->view->getFileInfo('/');
     $oldInfo2 = $this->view->getFileInfo('/foo');
     $oldInfo3 = $this->view->getFileInfo('/foo/bar');
     $time = time() + 50;
     $this->propagator->addChange('/foo/bar/sad.txt');
     $this->propagator->propagateChanges($time);
     $newInfo1 = $this->view->getFileInfo('/');
     $newInfo2 = $this->view->getFileInfo('/foo');
     $newInfo3 = $this->view->getFileInfo('/foo/bar');
     $this->assertEquals($newInfo1->getMTime(), $time);
     $this->assertEquals($newInfo2->getMTime(), $time);
     $this->assertEquals($newInfo3->getMTime(), $time);
     $this->assertNotSame($oldInfo1->getEtag(), $newInfo1->getEtag());
     $this->assertNotSame($oldInfo2->getEtag(), $newInfo2->getEtag());
     $this->assertNotSame($oldInfo3->getEtag(), $newInfo3->getEtag());
 }
 /**
  * @param array $share
  * @param string $internalPath
  * @param \OC\Files\Cache\ChangePropagator $propagator
  */
 private function propagateForOwner($share, $internalPath, ChangePropagator $propagator)
 {
     // note that we have already set up the filesystem for the owner when mounting the share
     $view = new View('/' . $share['uid_owner'] . '/files');
     $shareRootPath = $view->getPath($share['item_source']);
     if (!is_null($shareRootPath)) {
         $path = $shareRootPath . '/' . $internalPath;
         $path = Filesystem::normalizePath($path);
         $propagator->addChange($path);
         $propagator->propagateChanges();
     }
 }
Beispiel #5
0
 /**
  * Update etags for mount points for known user
  * For global or group mount points, updating the etag for every user is not feasible
  * instead we mark the mount point as dirty and update the etag when the filesystem is loaded for the user
  * For personal mount points, the change is propagated directly
  *
  * @param array $params hook parameters
  * @param int $time update time to use when marking a mount point as dirty
  */
 public function updateHook($params, $time = null)
 {
     if ($time === null) {
         $time = time();
     }
     $users = $params[Filesystem::signal_param_users];
     $type = $params[Filesystem::signal_param_mount_type];
     $mountPoint = $params[Filesystem::signal_param_path];
     $mountPoint = Filesystem::normalizePath($mountPoint);
     if ($type === \OC_Mount_Config::MOUNT_TYPE_GROUP or $users === 'all') {
         $this->markDirty($mountPoint, $time);
     } else {
         $this->changePropagator->addChange($mountPoint);
         $this->changePropagator->propagateChanges($time);
     }
 }
Beispiel #6
0
	public function testDontLowerMtime() {
		$time = time();
		$this->view->mkdir('/foo');
		$this->view->mkdir('/foo/bar');

		$cache = $this->storage->getCache();
		$cache->put('', ['mtime' => $time - 50]);
		$cache->put('foo', ['mtime' => $time - 150]);
		$cache->put('foo/bar', ['mtime' => $time - 250]);

		$this->propagator->addChange('/foo/bar/foo');
		$this->propagator->propagateChanges($time - 100);

		$this->assertEquals(50, $time - $cache->get('')['mtime']);
		$this->assertEquals(100, $time - $cache->get('foo')['mtime']);
		$this->assertEquals(100, $time - $cache->get('foo/bar')['mtime']);
	}
Beispiel #7
0
	/**
	 * Rename a file or folder in the cache and update the size, etag and mtime of the parent folders
	 *
	 * @param string $source
	 * @param string $target
	 */
	public function rename($source, $target) {
		if (!$this->enabled or Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) {
			return;
		}
		/**
		 * @var \OC\Files\Storage\Storage $sourceStorage
		 * @var \OC\Files\Storage\Storage $targetStorage
		 * @var string $sourceInternalPath
		 * @var string $targetInternalPath
		 */
		list($sourceStorage, $sourceInternalPath) = $this->view->resolvePath($source);
		// if it's a moved mountpoint we dont need to do anything
		if ($sourceInternalPath === '') {
			return;
		}
		list($targetStorage, $targetInternalPath) = $this->view->resolvePath($target);

		if ($sourceStorage && $targetStorage) {
			$targetCache = $targetStorage->getCache($sourceInternalPath);
			if ($sourceStorage->getCache($sourceInternalPath)->inCache($sourceInternalPath)) {
				if ($targetCache->inCache($targetInternalPath)) {
					$targetCache->remove($targetInternalPath);
				}
				if ($sourceStorage === $targetStorage) {
					$targetCache->move($sourceInternalPath, $targetInternalPath);
				} else {
					$targetCache->moveFromCache($sourceStorage->getCache(), $sourceInternalPath, $targetInternalPath);
				}
			}

			if (pathinfo($sourceInternalPath, PATHINFO_EXTENSION) !== pathinfo($targetInternalPath, PATHINFO_EXTENSION)) {
				// handle mime type change
				$mimeType = $targetStorage->getMimeType($targetInternalPath);
				$fileId = $targetCache->getId($targetInternalPath);
				$targetCache->update($fileId, array('mimetype' => $mimeType));
			}

			$targetCache->correctFolderSize($sourceInternalPath);
			$targetCache->correctFolderSize($targetInternalPath);
			$this->correctParentStorageMtime($sourceStorage, $sourceInternalPath);
			$this->correctParentStorageMtime($targetStorage, $targetInternalPath);
			$this->propagator->addChange($this->getPropagatorPath($source));
			$this->propagator->addChange($this->getPropagatorPath($target));
			$this->propagator->propagateChanges();
		}
	}