Merge pull request #69 from icewind1991/prefer-dir

use dir instead of allinfo where possible
This commit is contained in:
Robin Appelman 2018-08-24 15:22:16 +02:00 committed by GitHub
commit 14452ee7b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

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,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