From 4126ef22175c66c6f4018182cba05473f7af5dda Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Aug 2018 15:10:38 +0200 Subject: [PATCH 1/4] use dir instead of allinfo where possible --- src/Wrapped/Share.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Wrapped/Share.php b/src/Wrapped/Share.php index ec27815..c0c1869 100644 --- a/src/Wrapped/Share.php +++ b/src/Wrapped/Share.php @@ -13,10 +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\IFileInfo; use Icewind\SMB\INotifyHandler; use Icewind\SMB\IServer; use Icewind\SMB\ISystem; -use Icewind\SMB\TimeZoneProvider; use Icewind\Streams\CallbackWrapper; class Share extends AbstractShare { @@ -154,6 +154,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 From c7f89d014c92fda69bc30091147fc97553501a74 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Aug 2018 15:12:43 +0200 Subject: [PATCH 2/4] assume local timezone for local hostnames --- src/TimeZoneProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) From a91de0d0127072f2ed73453728a0b0b5076e7263 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Aug 2018 15:18:12 +0200 Subject: [PATCH 3/4] remove setter from option interface --- src/IOptions.php | 5 ----- 1 file changed, 5 deletions(-) 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); } From 24e0162914bade3fb657c94a2780e8c5ca486395 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 24 Aug 2018 15:20:33 +0200 Subject: [PATCH 4/4] respect timeout in native backend --- src/Native/NativeServer.php | 2 +- src/Native/NativeShare.php | 2 +- src/Native/NativeState.php | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) 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 3b5cca8..6f50877 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());