mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Merge pull request #46 from icewind1991/stream-stat
use regular stat instead of fstat
This commit is contained in:
commit
764f3fc793
2 changed files with 17 additions and 7 deletions
|
|
@ -239,8 +239,9 @@ class NativeShare extends AbstractShare {
|
||||||
*/
|
*/
|
||||||
public function read($source) {
|
public function read($source) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
$handle = $this->state->open($this->buildUrl($source), 'r');
|
$url = $this->buildUrl($source);
|
||||||
return NativeStream::wrap($this->state, $handle, 'r');
|
$handle = $this->state->open($url, 'r');
|
||||||
|
return NativeStream::wrap($this->state, $handle, 'r', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -254,8 +255,9 @@ class NativeShare extends AbstractShare {
|
||||||
*/
|
*/
|
||||||
public function write($source) {
|
public function write($source) {
|
||||||
$this->connect();
|
$this->connect();
|
||||||
$handle = $this->state->create($this->buildUrl($source));
|
$url = $this->buildUrl($source);
|
||||||
return NativeStream::wrap($this->state, $handle, 'w');
|
$handle = $this->state->create($url);
|
||||||
|
return NativeStream::wrap($this->state, $handle, 'w', $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -32,20 +32,27 @@ class NativeStream implements File {
|
||||||
*/
|
*/
|
||||||
private $eof = false;
|
private $eof = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap a stream from libsmbclient-php into a regular php stream
|
* Wrap a stream from libsmbclient-php into a regular php stream
|
||||||
*
|
*
|
||||||
* @param \Icewind\SMB\NativeState $state
|
* @param \Icewind\SMB\NativeState $state
|
||||||
* @param resource $smbStream
|
* @param resource $smbStream
|
||||||
* @param string $mode
|
* @param string $mode
|
||||||
|
* @param string $url
|
||||||
* @return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
public static function wrap($state, $smbStream, $mode) {
|
public static function wrap($state, $smbStream, $mode, $url) {
|
||||||
stream_wrapper_register('nativesmb', '\Icewind\SMB\NativeStream');
|
stream_wrapper_register('nativesmb', '\Icewind\SMB\NativeStream');
|
||||||
$context = stream_context_create(array(
|
$context = stream_context_create(array(
|
||||||
'nativesmb' => array(
|
'nativesmb' => array(
|
||||||
'state' => $state,
|
'state' => $state,
|
||||||
'handle' => $smbStream
|
'handle' => $smbStream,
|
||||||
|
'url' => $url
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
$fh = fopen('nativesmb://', $mode, false, $context);
|
$fh = fopen('nativesmb://', $mode, false, $context);
|
||||||
|
|
@ -69,6 +76,7 @@ class NativeStream implements File {
|
||||||
$context = stream_context_get_options($this->context);
|
$context = stream_context_get_options($this->context);
|
||||||
$this->state = $context['nativesmb']['state'];
|
$this->state = $context['nativesmb']['state'];
|
||||||
$this->handle = $context['nativesmb']['handle'];
|
$this->handle = $context['nativesmb']['handle'];
|
||||||
|
$this->url = $context['nativesmb']['url'];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +99,7 @@ class NativeStream implements File {
|
||||||
|
|
||||||
public function stream_stat() {
|
public function stream_stat() {
|
||||||
try {
|
try {
|
||||||
return $this->state->fstat($this->handle);
|
return $this->state->stat($this->url);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue