Exemplo n.º 1
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.º 2
0
	function testMove() {
		$file1 = 'folder';
		$file2 = 'folder/bar';
		$file3 = 'folder/foo';
		$file4 = 'folder/foo/1';
		$file5 = 'folder/foo/2';
		$data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar');
		$folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');

		$this->cache->put($file1, $folderData);
		$this->cache->put($file2, $folderData);
		$this->cache->put($file3, $folderData);
		$this->cache->put($file4, $data);
		$this->cache->put($file5, $data);

		/* simulate a second user with a different storage id but the same folder structure */
		$this->cache2->put($file1, $folderData);
		$this->cache2->put($file2, $folderData);
		$this->cache2->put($file3, $folderData);
		$this->cache2->put($file4, $data);
		$this->cache2->put($file5, $data);

		$this->cache->move('folder/foo', 'folder/foobar');

		$this->assertFalse($this->cache->inCache('folder/foo'));
		$this->assertFalse($this->cache->inCache('folder/foo/1'));
		$this->assertFalse($this->cache->inCache('folder/foo/2'));

		$this->assertTrue($this->cache->inCache('folder/bar'));
		$this->assertTrue($this->cache->inCache('folder/foobar'));
		$this->assertTrue($this->cache->inCache('folder/foobar/1'));
		$this->assertTrue($this->cache->inCache('folder/foobar/2'));

		/* the folder structure of the second user must not change! */
		$this->assertTrue($this->cache2->inCache('folder/bar'));
		$this->assertTrue($this->cache2->inCache('folder/foo'));
		$this->assertTrue($this->cache2->inCache('folder/foo/1'));
		$this->assertTrue($this->cache2->inCache('folder/foo/2'));

		$this->assertFalse($this->cache2->inCache('folder/foobar'));
		$this->assertFalse($this->cache2->inCache('folder/foobar/1'));
		$this->assertFalse($this->cache2->inCache('folder/foobar/2'));
	}
Exemplo n.º 3
0
 /**
  * @param string $name
  * @dataProvider escapingProvider
  */
 public function testEscaping($name)
 {
     $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain');
     $this->cache->put($name, $data);
     $this->assertTrue($this->cache->inCache($name));
     $retrievedData = $this->cache->get($name);
     foreach ($data as $key => $value) {
         $this->assertEquals($value, $retrievedData[$key]);
     }
     $this->cache->move($name, $name . 'asd');
     $this->assertFalse($this->cache->inCache($name));
     $this->assertTrue($this->cache->inCache($name . 'asd'));
     $this->cache->remove($name . 'asd');
     $this->assertFalse($this->cache->inCache($name . 'asd'));
     $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
     $this->cache->put($name, $folderData);
     $this->cache->put('other', $folderData);
     $childs = ['asd', 'bar', 'foo', 'sub/folder'];
     $this->cache->put($name . '/sub', $folderData);
     $this->cache->put('other/sub', $folderData);
     foreach ($childs as $child) {
         $this->cache->put($name . '/' . $child, $data);
         $this->cache->put('other/' . $child, $data);
         $this->assertTrue($this->cache->inCache($name . '/' . $child));
     }
     $this->cache->move($name, $name . 'asd');
     foreach ($childs as $child) {
         $this->assertTrue($this->cache->inCache($name . 'asd/' . $child));
         $this->assertTrue($this->cache->inCache('other/' . $child));
     }
     foreach ($childs as $child) {
         $this->cache->remove($name . 'asd/' . $child);
         $this->assertFalse($this->cache->inCache($name . 'asd/' . $child));
         $this->assertTrue($this->cache->inCache('other/' . $child));
     }
 }
Exemplo n.º 4
0
 /**
  * Move a file or folder in the cache
  *
  * @param string $source
  * @param string $target
  */
 public function move($source, $target)
 {
     $this->cache->move($source, $target);
 }