Skip to content

Commit

Permalink
Merge branch 'permission' of https://github.com/voda/vfsStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Kleine committed May 9, 2012
2 parents 09c40dd + 96699af commit 4ea158c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/main/php/org/bovigo/vfs/vfsStreamWrapper.php
Expand Up @@ -249,12 +249,18 @@ public function stream_open($path, $mode, $options, $opened_path)
) {
return false;
}

if (self::TRUNCATE === $mode) {
$this->content->openWithTruncate();
} elseif (self::APPEND === $mode) {
$this->content->openForAppend();
} else {
if (!$this->content->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
trigger_error('Permission denied', E_USER_WARNING);
}
return false;
}
$this->content->open();
}

Expand Down Expand Up @@ -572,23 +578,25 @@ public function rename($path_from, $path_to)
trigger_error(' No such file or directory', E_USER_WARNING);
return false;
}

$dstContent = clone $srcContent;
$dstNames = $this->splitPath($dstRealPath);
// Renaming the filename
$dstContent->rename($dstNames['basename']);
// Copying to the destination
$dstNames = $this->splitPath($dstRealPath);
$dstParentContent = $this->getContent($dstNames['dirname']);
if (null == $dstParentContent) {
trigger_error('No such file or directory', E_USER_WARNING);
return false;
}

if (!$dstParentContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
trigger_error('Permission denied', E_USER_WARNING);
return false;
}
if ($dstParentContent->getType() !== vfsStreamContent::TYPE_DIR) {
trigger_error('Target is not a directory', E_USER_WARNING);
return false;
}

$dstContent = clone $srcContent;
// Renaming the filename
$dstContent->rename($dstNames['basename']);
// Copying to the destination
$dstParentContent->addChild($dstContent);
// Removing the source
return $this->doUnlink($srcRealPath);
Expand Down
27 changes: 27 additions & 0 deletions src/test/php/org/bovigo/vfs/vfsStreamWrapperFileTestCase.php
Expand Up @@ -439,5 +439,32 @@ public function cannotOpenExistingNonwritableFileWithModeW()
$this->baz1->chmod(0400);
$this->assertFalse(@fopen($this->baz1URL, 'w'));
}

/**
* @test
*/
public function cannotOpenNonReadableFileWithModeR()
{
$this->baz1->chmod(0);
$this->assertFalse(@fopen($this->baz1URL, 'r'));
}

/**
* @test
*/
public function cannotRenameToNonWritableDir()
{
$this->bar->chmod(0);
$this->assertFalse(@rename($this->baz2URL, vfsStream::url('foo/bar/baz3')));
}

/**
* @test
*/
public function cannotReadFileFromNonReadableDir()
{
$this->bar->chmod(0);
$this->assertFalse(@file_get_contents($this->baz1URL));
}
}
?>

0 comments on commit 4ea158c

Please sign in to comment.