Skip to content

Commit

Permalink
CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Aug 24, 2019
1 parent bafc949 commit 4dc7c25
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.php_cs.cache
php-cs-fixer
bin
composer.lock
coverage
Expand Down
20 changes: 11 additions & 9 deletions src/Adapter/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use DirectoryIterator;
use FilesystemIterator;
use finfo as Finfo;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\Exception;
use League\Flysystem\NotSupportedException;
Expand Down Expand Up @@ -343,14 +342,17 @@ public function getVisibility($path)
$location = $this->applyPathPrefix($path);
clearstatcache(false, $location);
$permissions = octdec(substr(sprintf('%o', fileperms($location)), -4));
$type = is_dir($location) ? 'dir' : 'file';

foreach ($this->permissionMap[$type] as $visibility => $visibilityPermissions)
if ($visibilityPermissions == $permissions)
return compact('path', 'visibility');

$visibility = substr(sprintf('%o', fileperms($location)), -4);
return compact('path', 'visibility');
$type = is_dir($location) ? 'dir' : 'file';

foreach ($this->permissionMap[$type] as $visibility => $visibilityPermissions) {
if ($visibilityPermissions == $permissions) {
return compact('path', 'visibility');
}
}

$visibility = substr(sprintf('%o', fileperms($location)), -4);

return compact('path', 'visibility');
}

/**
Expand Down
82 changes: 42 additions & 40 deletions tests/LocalAdapterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace League\Flysystem\Adapter;

use League\Flysystem\Config;
use League\Flysystem\FileNotFoundException;
use League\Flysystem\Filesystem;
use PHPUnit\Framework\TestCase;

function fopen($result, $mode)
Expand Down Expand Up @@ -233,7 +231,7 @@ public function testNotWritableRoot()
}

try {
$root = $this->root. 'not-writable';
$root = $this->root . 'not-writable';
mkdir($root, 0000, true);
$this->expectException('LogicException');
new Local($root);
Expand Down Expand Up @@ -374,97 +372,101 @@ public function testVisibilityFail()
$this->adapter->setVisibility('chmod.fail', 'public')
);
}

public function testUnknownVisibility()
{
if (IS_WINDOWS)
if (IS_WINDOWS) {
$this->markTestSkipped("Visibility not supported on Windows.");

$umask = umask(0);
mkdir($this->root.'subdir', 0750);
}

$umask = umask(0);
mkdir($this->root . 'subdir', 0750);
umask($umask);

$output = $this->adapter->getVisibility('subdir');

$this->assertNotEquals('private', $output['visibility']); // private is 0700 not 0750
$this->assertNotEquals('public', $output['visibility']); // public is 0755 not 0750
$this->assertEquals('0750', $output['visibility']);
}

public function testCustomizedVisibility()
{
if (IS_WINDOWS)
if (IS_WINDOWS) {
$this->markTestSkipped("Visibility not supported on Windows.");

// override a permission mapping
}

// override a permission mapping
$permissions = [
'dir' => [
'private' => 0770, // private to me and the gang
],
];

$adapter = new Local($this->root, LOCK_EX, Local::DISALLOW_LINKS, $permissions);

$adapter->createDir('private-dir', new Config());
$adapter->setVisibility('private-dir', 'private');

$output = $adapter->getVisibility('private-dir');
$this->assertEquals('private', $output['visibility']);
$this->assertEquals('0770', substr(sprintf('%o', fileperms($this->root.'private-dir')), -4));

$this->assertEquals('private', $output['visibility']);
$this->assertEquals('0770', substr(sprintf('%o', fileperms($this->root . 'private-dir')), -4));
}

public function testCustomVisibility()
{
if (IS_WINDOWS)
if (IS_WINDOWS) {
$this->markTestSkipped("Visibility not supported on Windows.");

// add a permission mapping
}

// add a permission mapping
$permissions = [
'dir' => [
'yolo' => 0777,
'yolo' => 0777,
],
];

$adapter = new Local($this->root, LOCK_EX, Local::DISALLOW_LINKS, $permissions);

$adapter->createDir('yolo-dir', new Config());
$adapter->setVisibility('yolo-dir', 'yolo');
$location = $this->root.'yolo-dir';

$location = $this->root . 'yolo-dir';

$output = $adapter->getVisibility('yolo-dir');
$this->assertEquals('yolo', $output['visibility']);
$this->assertEquals('0777', substr(sprintf('%o', fileperms($location)), -4));
$this->assertEquals('0777', substr(sprintf('%o', fileperms($location)), -4));
}

public function testFirstVisibilityOctet()
{
if (IS_WINDOWS)
if (IS_WINDOWS) {
$this->markTestSkipped("Visibility not supported on Windows.");

}

$permissions = [
'file' => [
'public' => 0644,
'private' => 0600,
],
'dir' => [
'sticky' => 01777,
'sticky' => 01777,
'public' => 0755,
'private' => 0700,
],
];

$adapter = new Local($this->root, LOCK_EX, Local::DISALLOW_LINKS, $permissions);

$adapter->createDir('sticky-dir', new Config());
$adapter->setVisibility('sticky-dir', 'sticky');

$output = $adapter->getVisibility('sticky-dir');
$this->assertEquals('sticky', $output['visibility']);
$this->assertEquals('1777', substr(sprintf('%o', fileperms($this->root.'sticky-dir')), -4));
$this->assertEquals('1777', substr(sprintf('%o', fileperms($this->root . 'sticky-dir')), -4));
}

public function testApplyPathPrefix()
{
$this->adapter->setPathPrefix('');
Expand Down

0 comments on commit 4dc7c25

Please sign in to comment.