Merge remote-tracking branch 'upstream/master'

Conflicts:
	src/Wrapped/Share.php
This commit is contained in:
Raffael Sahli 2018-08-24 16:40:28 +02:00
commit 9002120613
6 changed files with 22 additions and 11 deletions

View file

@ -26,9 +26,4 @@ interface IOptions {
* @return int
*/
public function getTimeout();
/**
* @param int $timeout
*/
public function setTimeout($timeout);
}

View file

@ -25,7 +25,7 @@ class NativeServer extends AbstractServer {
}
protected function connect() {
$this->state->init($this->getAuth());
$this->state->init($this->getAuth(), $this->getOptions());
}
/**

View file

@ -53,7 +53,7 @@ class NativeShare extends AbstractShare {
}
$this->state = new NativeState();
$this->state->init($this->server->getAuth());
$this->state->init($this->server->getAuth(), $this->server->getOptions());
return $this->state;
}

View file

@ -21,6 +21,7 @@ use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\Exception\OutOfSpaceException;
use Icewind\SMB\Exception\TimedOutException;
use Icewind\SMB\IAuth;
use Icewind\SMB\IOptions;
/**
* Low level wrapper for libsmbclient-php with error handling
@ -76,14 +77,16 @@ class NativeState {
/**
* @param IAuth $auth
* @param IOptions $options
* @return bool
*/
public function init(IAuth $auth) {
public function init(IAuth $auth, IOptions $options) {
if ($this->connected) {
return true;
}
$this->state = smbclient_state_new();
smbclient_option_set($this->state, SMBCLIENT_OPT_AUTO_ANONYMOUS_LOGIN, false);
smbclient_option_set($this->state, SMBCLIENT_OPT_TIMEOUT, $options->getTimeout() * 1000);
$auth->setExtraSmbClientOptions($this->state);
$result = @smbclient_state_init($this->state, $auth->getWorkgroup(), $auth->getUsername(), $auth->getPassword());

View file

@ -28,7 +28,8 @@ class TimeZoneProvider implements ITimeZoneProvider {
public function get($host) {
if (!isset($this->timeZones[$host])) {
$net = $this->system->getNetPath();
if ($net && $host) {
// for local domain names we can assume same timezone
if ($net && $host && strpos($host, '.') !== false) {
$command = sprintf('%s time zone -S %s',
$net,
escapeshellarg($host)

View file

@ -13,11 +13,10 @@ use Icewind\SMB\Exception\DependencyException;
use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\InvalidTypeException;
use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\Exception\InvalidRequestException;
use Icewind\SMB\IFileInfo;
use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IServer;
use Icewind\SMB\ISystem;
use Icewind\SMB\TimeZoneProvider;
use Icewind\Streams\CallbackWrapper;
use Icewind\SMB\Native\NativeShare;
use Icewind\SMB\Native\NativeServer;
@ -157,6 +156,19 @@ class Share extends AbstractShare {
* @return \Icewind\SMB\IFileInfo
*/
public function stat($path) {
// some windows server setups don't seem to like the allinfo command
// use the dir command instead to get the file info where possible
if ($path !== "" && $path !== "/") {
$parent = dirname($path);
$dir = $this->dir($parent);
$file = array_values(array_filter($dir, function(IFileInfo $info) use ($path) {
return $info->getPath() === $path;
}));
if ($file) {
return $file[0];
}
}
$escapedPath = $this->escapePath($path);
$output = $this->execute('allinfo ' . $escapedPath);
// Windows and non Windows Fileserver may respond different