diff --git a/src/IOptions.php b/src/IOptions.php index 0ee0b8e..c46d2c8 100644 --- a/src/IOptions.php +++ b/src/IOptions.php @@ -26,9 +26,4 @@ interface IOptions { * @return int */ public function getTimeout(); - - /** - * @param int $timeout - */ - public function setTimeout($timeout); } diff --git a/src/Native/NativeServer.php b/src/Native/NativeServer.php index 1a6dec6..a5b502b 100644 --- a/src/Native/NativeServer.php +++ b/src/Native/NativeServer.php @@ -25,7 +25,7 @@ class NativeServer extends AbstractServer { } protected function connect() { - $this->state->init($this->getAuth()); + $this->state->init($this->getAuth(), $this->getOptions()); } /** diff --git a/src/Native/NativeShare.php b/src/Native/NativeShare.php index e980ebf..27efa80 100644 --- a/src/Native/NativeShare.php +++ b/src/Native/NativeShare.php @@ -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; } diff --git a/src/Native/NativeState.php b/src/Native/NativeState.php index 179ba95..5ab129c 100644 --- a/src/Native/NativeState.php +++ b/src/Native/NativeState.php @@ -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()); diff --git a/src/TimeZoneProvider.php b/src/TimeZoneProvider.php index b62a904..14deb57 100644 --- a/src/TimeZoneProvider.php +++ b/src/TimeZoneProvider.php @@ -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) diff --git a/src/Wrapped/Share.php b/src/Wrapped/Share.php index e1e489a..8cfae89 100644 --- a/src/Wrapped/Share.php +++ b/src/Wrapped/Share.php @@ -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