Exemple #1
0
 public function testWriteNotEnoughSpaceExistingStreamRewind()
 {
     $source = fopen('php://temp', 'w+');
     fwrite($source, 'foobar');
     $stream = \OC\Files\Stream\Quota::wrap($source, 3);
     rewind($stream);
     $this->assertEquals(6, fwrite($stream, 'qwerty'));
     rewind($stream);
     $this->assertEquals('qwerty', fread($stream, 100));
 }
Exemple #2
0
 private function doTestCopyRenameFail($operation)
 {
     $storage1 = new Temporary(array());
     /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage2 */
     $storage2 = $this->getMockBuilder('\\Test\\Files\\TemporaryNoCross')->setConstructorArgs([[]])->setMethods(['fopen'])->getMock();
     $storage2->expects($this->any())->method('fopen')->will($this->returnCallback(function ($path, $mode) use($storage2) {
         /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage2 */
         $source = fopen($storage2->getSourcePath($path), $mode);
         return \OC\Files\Stream\Quota::wrap($source, 9);
     }));
     $storage1->mkdir('sub');
     $storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH');
     $storage1->mkdir('dirtomove');
     $storage1->file_put_contents('dirtomove/indir1.txt', '0123456');
     // fits
     $storage1->file_put_contents('dirtomove/indir2.txt', '0123456789ABCDEFGH');
     // doesn't fit
     $storage2->file_put_contents('existing.txt', '0123');
     $storage1->getScanner()->scan('');
     $storage2->getScanner()->scan('');
     \OC\Files\Filesystem::mount($storage1, array(), '/test/');
     \OC\Files\Filesystem::mount($storage2, array(), '/test/sub/storage');
     // move file
     $view = new \OC\Files\View('');
     $this->assertTrue($storage1->file_exists('foo.txt'));
     $this->assertFalse($storage2->file_exists('foo.txt'));
     $this->assertFalse($view->{$operation}('/test/foo.txt', '/test/sub/storage/foo.txt'));
     $this->assertFalse($storage2->file_exists('foo.txt'));
     $this->assertFalse($storage2->getCache()->get('foo.txt'));
     $this->assertTrue($storage1->file_exists('foo.txt'));
     // if target exists, it will be deleted too
     $this->assertFalse($view->{$operation}('/test/foo.txt', '/test/sub/storage/existing.txt'));
     $this->assertFalse($storage2->file_exists('existing.txt'));
     $this->assertFalse($storage2->getCache()->get('existing.txt'));
     $this->assertTrue($storage1->file_exists('foo.txt'));
     // move folder
     $this->assertFalse($view->{$operation}('/test/dirtomove/', '/test/sub/storage/dirtomove/'));
     // since the move failed, the full source tree is kept
     $this->assertTrue($storage1->file_exists('dirtomove/indir1.txt'));
     $this->assertTrue($storage1->file_exists('dirtomove/indir2.txt'));
     // second file not moved/copied
     $this->assertFalse($storage2->file_exists('dirtomove/indir2.txt'));
     $this->assertFalse($storage2->getCache()->get('dirtomove/indir2.txt'));
 }
Exemple #3
0
 /**
  * see http://php.net/manual/en/function.fopen.php
  *
  * @param string $path
  * @param string $mode
  * @return resource
  */
 public function fopen($path, $mode)
 {
     $source = $this->storage->fopen($path, $mode);
     $free = $this->free_space('');
     if ($source && $free >= 0 && $mode !== 'r' && $mode !== 'rb') {
         // only apply quota for files, not metadata, trash or others
         if (strpos(ltrim($path, '/'), 'files/') === 0) {
             return \OC\Files\Stream\Quota::wrap($source, $free);
         }
     }
     return $source;
 }
Exemple #4
0
 /**
  * see http://php.net/manual/en/function.fopen.php
  *
  * @param string $path
  * @param string $mode
  * @return resource
  */
 public function fopen($path, $mode)
 {
     $source = $this->storage->fopen($path, $mode);
     $free = $this->free_space('');
     if ($free >= 0 && $mode !== 'r') {
         return \OC\Files\Stream\Quota::wrap($source, $free);
     } else {
         return $source;
     }
 }