handle new share list output

This commit is contained in:
Robin Appelman 2018-03-27 17:25:21 +02:00
commit 89f47cfdf2
4 changed files with 27 additions and 6 deletions

View file

@ -17,10 +17,10 @@ class System {
private $stdbuf;
public static function getFD($num) {
$folders = array(
$folders = [
'/proc/self/fd',
'/dev/fd'
);
];
foreach ($folders as $folder) {
if (file_exists($folder)) {
return $folder . '/' . $num;

View file

@ -166,6 +166,10 @@ class Parser {
if (strtolower($type) === 'disk') {
$shareNames[$name] = $description;
}
} else if (strpos($line, 'Disk')) {
// new output format
list($name, $description) = explode('Disk', $line);
$shareNames[trim($name)] = trim($description);
}
}
return $shareNames;

View file

@ -49,6 +49,9 @@ class RawConnection {
$this->env = $env;
}
/**
* @throws ConnectException
*/
public function connect() {
if (is_null($this->getAuthStream())) {
throw new ConnectException('Authentication not set before connecting');

View file

@ -8,12 +8,18 @@
namespace Icewind\SMB\Wrapped;
use Icewind\SMB\AbstractServer;
use Icewind\SMB\Exception\AuthenticationException;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\ConnectionException;
use Icewind\SMB\Exception\InvalidHostException;
use Icewind\SMB\IShare;
use Icewind\SMB\System;
class Server extends AbstractServer {
/**
* Check if the smbclient php extension is available
*
* @param System $system
* @return bool
*/
public static function available(System $system) {
@ -29,10 +35,11 @@ class Server extends AbstractServer {
}
/**
* @return \Icewind\SMB\IShare[]
* @return IShare[]
*
* @throws \Icewind\SMB\Exception\AuthenticationException
* @throws \Icewind\SMB\Exception\InvalidHostException
* @throws AuthenticationException
* @throws InvalidHostException
* @throws ConnectException
*/
public function listShares() {
$command = sprintf('%s %s %s -L %s',
@ -44,7 +51,14 @@ class Server extends AbstractServer {
$connection = new RawConnection($command);
$connection->writeAuthentication($this->getAuth()->getUsername(), $this->getAuth()->getPassword());
$connection->connect();
if (!$connection->isValid()) {
throw new ConnectionException($connection->readLine());
}
$output = $connection->readAll();
// sometimes we get an empty line first
if (count($output) === 0) {
$output = $connection->readAll();
}
$parser = new Parser($this->timezoneProvider);
if (isset($output[0])) {
@ -62,7 +76,7 @@ class Server extends AbstractServer {
/**
* @param string $name
* @return \Icewind\SMB\IShare
* @return IShare
*/
public function getShare($name) {
return new Share($this, $name, $this->system);