Exemple #1
0
	public function testMoveCrossStorage() {
		$storage2 = new Temporary(array());
		$cache2 = $storage2->getCache();
		Filesystem::mount($storage2, array(), '/bar');
		$this->storage->file_put_contents('foo.txt', 'qwerty');

		$this->updater->update('foo.txt');

		$this->assertTrue($this->cache->inCache('foo.txt'));
		$this->assertFalse($cache2->inCache('bar.txt'));
		$cached = $this->cache->get('foo.txt');

		// "rename"
		$storage2->file_put_contents('bar.txt', 'qwerty');
		$this->storage->unlink('foo.txt');

		$this->assertTrue($this->cache->inCache('foo.txt'));
		$this->assertFalse($cache2->inCache('bar.txt'));

		$this->updater->rename('foo.txt', 'bar/bar.txt');

		$this->assertFalse($this->cache->inCache('foo.txt'));
		$this->assertTrue($cache2->inCache('bar.txt'));

		$cachedTarget = $cache2->get('bar.txt');
		$this->assertEquals($cached['mtime'], $cachedTarget['mtime']);
		$this->assertEquals($cached['size'], $cachedTarget['size']);
		$this->assertEquals($cached['etag'], $cachedTarget['etag']);
		$this->assertEquals($cached['fileid'], $cachedTarget['fileid']);
	}
Exemple #2
0
 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'));
 }
Exemple #3
0
 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']);
 }
Exemple #4
0
	/**
	 * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage
	 *
	 * @param string $operation
	 * @param string $path
	 * @param array $hooks (optional)
	 * @param mixed $extraParam (optional)
	 * @return mixed
	 *
	 * This method takes requests for basic filesystem functions (e.g. reading & writing
	 * files), processes hooks and proxies, sanitises paths, and finally passes them on to
	 * \OC\Files\Storage\Storage for delegation to a storage backend for execution
	 */
	private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) {
		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
		if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
			and Filesystem::isValidPath($path)
			and !Filesystem::isFileBlacklisted($path)
		) {
			$path = $this->getRelativePath($absolutePath);
			if ($path == null) {
				return false;
			}

			$run = $this->runHooks($hooks, $path);
			list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
			if ($run and $storage) {
				if (!is_null($extraParam)) {
					$result = $storage->$operation($internalPath, $extraParam);
				} else {
					$result = $storage->$operation($internalPath);
				}

				$result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);

				if (in_array('delete', $hooks) and $result) {
					$this->updater->remove($path);
				}
				if (in_array('write', $hooks)) {
					$this->updater->update($path);
				}
				if (in_array('touch', $hooks)) {
					$this->updater->update($path, $extraParam);
				}

				if ($this->shouldEmitHooks($path) && $result !== false) {
					if ($operation != 'fopen') { //no post hooks for fopen, the file stream is still open
						$this->runHooks($hooks, $path, true);
					}
				}
				return $result;
			}
		}
		return null;
	}
Exemple #5
0
 /**
  * abstraction layer for basic filesystem functions: wrapper for \OC\Files\Storage\Storage
  *
  * @param string $operation
  * @param string $path
  * @param array $hooks (optional)
  * @param mixed $extraParam (optional)
  * @return mixed
  *
  * This method takes requests for basic filesystem functions (e.g. reading & writing
  * files), processes hooks and proxies, sanitises paths, and finally passes them on to
  * \OC\Files\Storage\Storage for delegation to a storage backend for execution
  */
 private function basicOperation($operation, $path, $hooks = array(), $extraParam = null)
 {
     $postFix = substr($path, -1, 1) === '/' ? '/' : '';
     $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
     if (Filesystem::isValidPath($path) and !Filesystem::isFileBlacklisted($path)) {
         $path = $this->getRelativePath($absolutePath);
         if ($path == null) {
             return false;
         }
         if (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks)) {
             // always a shared lock during pre-hooks so the hook can read the file
             $this->lockFile($path, ILockingProvider::LOCK_SHARED);
         }
         $run = $this->runHooks($hooks, $path);
         list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
         if ($run and $storage) {
             if (in_array('write', $hooks) || in_array('delete', $hooks)) {
                 $this->changeLock($path, ILockingProvider::LOCK_EXCLUSIVE);
             }
             try {
                 if (!is_null($extraParam)) {
                     $result = $storage->{$operation}($internalPath, $extraParam);
                 } else {
                     $result = $storage->{$operation}($internalPath);
                 }
             } catch (\Exception $e) {
                 if (in_array('write', $hooks) || in_array('delete', $hooks)) {
                     $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
                 } else {
                     if (in_array('read', $hooks)) {
                         $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
                     }
                 }
                 throw $e;
             }
             if (in_array('delete', $hooks) and $result) {
                 $this->updater->remove($path);
             }
             if (in_array('write', $hooks) and $operation !== 'fopen') {
                 $this->updater->update($path);
             }
             if (in_array('touch', $hooks)) {
                 $this->updater->update($path, $extraParam);
             }
             if ((in_array('write', $hooks) || in_array('delete', $hooks)) && ($operation !== 'fopen' || $result === false)) {
                 $this->changeLock($path, ILockingProvider::LOCK_SHARED);
             }
             $unlockLater = false;
             if ($this->lockingEnabled && $operation === 'fopen' && is_resource($result)) {
                 $unlockLater = true;
                 $result = CallbackWrapper::wrap($result, null, null, function () use($hooks, $path) {
                     if (in_array('write', $hooks)) {
                         $this->unlockFile($path, ILockingProvider::LOCK_EXCLUSIVE);
                     } else {
                         if (in_array('read', $hooks)) {
                             $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
                         }
                     }
                 });
             }
             if ($this->shouldEmitHooks($path) && $result !== false) {
                 if ($operation != 'fopen') {
                     //no post hooks for fopen, the file stream is still open
                     $this->runHooks($hooks, $path, true);
                 }
             }
             if (!$unlockLater && (in_array('write', $hooks) || in_array('delete', $hooks) || in_array('read', $hooks))) {
                 $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
             }
             return $result;
         } else {
             $this->unlockFile($path, ILockingProvider::LOCK_SHARED);
         }
     }
     return null;
 }