Skip to content

Commit

Permalink
Fix permission issues
Browse files Browse the repository at this point in the history
Pickle now uses its own sandbox to download extensions' sources

Closes #123
  • Loading branch information
jubianchi committed Nov 24, 2015
1 parent 77849fe commit 802ba31
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/Base/Abstracts/Package/Convey/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public function __construct($path, ConsoleIO $io)

abstract protected function prepare();

public function execute($target, $no_convert)
{
throw new \Exception('No command::execute implementation found ');
}
abstract public function execute($target, $no_convert);

public function getPath()
{
Expand Down
22 changes: 22 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Pickle;

use Composer;

class Config extends Composer\Config
{
const DEFAULT_BASE_DIRNAME = '.pickle';

public function __construct($useEnvironment = true, $baseDir = null)
{
if ($useEnvironment === true) {
$baseDir = $baseDir ?: (getenv('PICKLE_BASE_DIR') ?: null);
}

$baseDir = $baseDir ?: (getenv('HOME') ?: sys_get_temp_dir());
$baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . self::DEFAULT_BASE_DIRNAME;

parent::__construct($useEnvironment, $baseDir);
}
}
4 changes: 2 additions & 2 deletions src/Console/Command/InstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function configure()
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function binaryInstallWindows($path, $input, $output)
protected function binaryInstallWindows($path, InputInterface $input, OutputInterface $output)
{
$php = Engine::factory();
$table = new Table($output);
Expand Down Expand Up @@ -194,7 +194,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$package = $this->getHelper('package')->convey($input, $output, $path);

/* TODO Info package command should be used here. */
/* TODO Info package command should be used here. */
$this->getHelper('package')->showInfo($output, $package);

list($optionsValue, $force_opts) = $this->buildOptions($package, $input, $output);
Expand Down
6 changes: 6 additions & 0 deletions src/Package/Convey/Command/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@

class Factory
{
/**
* @param $type
* @param $path
* @param ConsoleIO $io
* @return \Pickle\Base\Abstracts\Package\Convey\Command
*/
public static function getCommand($type, $path, ConsoleIO $io)
{
switch ($type) {
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Convey/Command/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace Pickle\Package\Convey\Command;

use Composer\Config;
use Pickle\Config;
use Pickle\Base\Abstracts;
use Pickle\Base\Interfaces;
use Pickle\Package;
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Convey/Command/Pickle.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace Pickle\Package\Convey\Command;

use Composer\Config;
use Pickle\Config;
use Pickle\Base\Abstracts;
use Pickle\Base\Interfaces;
use Pickle\Package;
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Convey/Command/Tgz.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace Pickle\Package\Convey\Command;

use Composer\Config;
use Pickle\Config;
use Pickle\Base\Interfaces;
use Pickle\Base\Abstracts;
use Pickle\Package;
Expand Down
2 changes: 1 addition & 1 deletion src/Package/PHP/Convey/Command/Pecl.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

namespace Pickle\Package\PHP\Convey\Command;

use Composer\Config;
use Pickle\Config;
use Pickle\Base\Interfaces;
use Pickle\Base\Abstracts;
use Pickle\Package\PHP;
Expand Down
73 changes: 73 additions & 0 deletions tests/units/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Pickle\tests\units;

use atoum;
use Pickle\Config as TestedClass;

class Config extends atoum
{
public function test__construct()
{
$this
->given(
$this->function->getenv = false,
$this->function->sys_get_temp_dir = $tmpDir = 'tmp'
)
->when($this->newTestedInstance(false))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($tmpDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->never
->when($this->newTestedInstance(true))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($tmpDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->once

->given($this->function->getenv = function($var) use (& $baseDir) { return $var === 'PICKLE_BASE_DIR' ? $baseDir = uniqid() : false; })
->when($this->newTestedInstance(false))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($tmpDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->once
->when($this->newTestedInstance(true))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->twice

->given($this->function->getenv = function($var) use (& $baseDir, & $homeDir) {
return $var === 'PICKLE_BASE_DIR' ? $baseDir = uniqid() : $homeDir = uniqid();
}
)
->when($this->newTestedInstance(false))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($homeDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->twice
->when($this->newTestedInstance(true))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->thrice

->when($this->newTestedInstance(false, $baseDir = uniqid()))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->thrice

->when($this->newTestedInstance(true, $baseDir = uniqid()))
->then
->string($this->testedInstance->get('vendor-dir'))->isEqualTo($this->makePath($baseDir, TestedClass::$defaultConfig['vendor-dir']))
->function('getenv')
->wasCalledWithArguments('PICKLE_BASE_DIR')->thrice
;
}

private function makePath($head, $tail)
{
return $head . DIRECTORY_SEPARATOR . TestedClass::DEFAULT_BASE_DIRNAME . DIRECTORY_SEPARATOR . $tail;
}
}

0 comments on commit 802ba31

Please sign in to comment.