Fix passing of locale

This commit is contained in:
Robin Appelman 2013-03-03 22:52:21 +01:00
commit 719dcf6ca9
3 changed files with 17 additions and 5 deletions

View file

@ -9,6 +9,9 @@
namespace SMB; namespace SMB;
class Connection { class Connection {
const DELIMITER = 'smb:';
/** /**
* @var resource[] $pipes * @var resource[] $pipes
* *
@ -26,12 +29,12 @@ class Connection {
public function __construct($command) { public function __construct($command) {
$descriptorSpec = array( $descriptorSpec = array(
0 => array("pipe", "r"), 0 => array("pipe", "r"),
1 => array("pipe", "w"), 1 => array("pipe", "w")
); );
putenv('LC_ALL=' . Server::LOCALE);
setlocale(LC_ALL, Server::LOCALE); setlocale(LC_ALL, Server::LOCALE);
$this->process = proc_open($command, $descriptorSpec, $this->pipes, null, array( $this->process = proc_open($command, $descriptorSpec, $this->pipes, null, array(
'CLI_FORCE_INTERACTIVE' => 'y' // Needed or the prompt isn't displayed!! 'CLI_FORCE_INTERACTIVE' => 'y', // Needed or the prompt isn't displayed!!
'LC_ALL' => Server::LOCALE
)); ));
if (!is_resource($this->process)) { if (!is_resource($this->process)) {
throw new ConnectionError(); throw new ConnectionError();
@ -58,7 +61,8 @@ class Connection {
fgets($this->pipes[1]); //first line is prompt fgets($this->pipes[1]); //first line is prompt
$output = array(); $output = array();
$line = fgets($this->pipes[1]); $line = fgets($this->pipes[1]);
while (substr($line, 0, 4) !== 'smb:') { //next prompt functions as delimiter $length = strlen(self::DELIMITER);
while (substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
$output[] .= $line; $output[] .= $line;
$line = fgets($this->pipes[1]); $line = fgets($this->pipes[1]);
} }

View file

@ -38,6 +38,13 @@ class Share {
$this->connection->write($this->server->getPassword()); $this->connection->write($this->server->getPassword());
} }
public function connect() {
$command = Server::CLIENT . ' -U ' . escapeshellarg($this->server->getUser()) .
' //' . $this->server->getHost() . '/' . $this->name;
$this->connection = new Connection($command);
$this->connection->write($this->server->getPassword());
}
public function getName() { public function getName() {
return $this->name; return $this->name;
} }

View file

@ -87,7 +87,7 @@ class Test extends PHPUnit_Framework_TestCase {
public function testEscaping() { public function testEscaping() {
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working // / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
$names = array('simple', 'with spaces', "single'quote'", '$as#d'); $names = array('simple', 'with spaces', "single'quote'", '$as#d', '€', '££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ');
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'; $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
$tmpFile1 = tempnam('/tmp', 'smb_test_'); $tmpFile1 = tempnam('/tmp', 'smb_test_');
@ -95,6 +95,7 @@ class Test extends PHPUnit_Framework_TestCase {
foreach ($names as $name) { foreach ($names as $name) {
$this->share->mkdir($this->root . '/' . $name); $this->share->mkdir($this->root . '/' . $name);
$this->share->connect();
$dir = $this->share->dir($this->root); $dir = $this->share->dir($this->root);
$this->assertArrayHasKey($name, $dir); $this->assertArrayHasKey($name, $dir);
$this->assertEquals('dir', $dir[$name]['type']); $this->assertEquals('dir', $dir[$name]['type']);