add proper paths to exceptions during stream close and write

This commit is contained in:
Robin Appelman 2020-04-08 17:20:22 +02:00
commit db50bb51bd
4 changed files with 15 additions and 12 deletions

View file

@ -197,12 +197,14 @@ class NativeShare extends AbstractShare {
*/ */
public function put($source, $target) { public function put($source, $target) {
$sourceHandle = fopen($source, 'rb'); $sourceHandle = fopen($source, 'rb');
$targetHandle = $this->getState()->create($this->buildUrl($target)); $targetUrl = $this->buildUrl($target);
$targetHandle = $this->getState()->create($targetUrl);
while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) { while ($data = fread($sourceHandle, NativeReadStream::CHUNK_SIZE)) {
$this->getState()->write($targetHandle, $data); $this->getState()->write($targetHandle, $data, $targetUrl);
} }
$this->getState()->close($targetHandle); $this->getState()->close($targetHandle, $targetUrl);
return true; return true;
} }
@ -236,14 +238,14 @@ class NativeShare extends AbstractShare {
} else { } else {
$reason = 'Unknown error'; $reason = 'Unknown error';
} }
$this->getState()->close($sourceHandle); $this->getState()->close($sourceHandle, $this->buildUrl($source));
throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason);
} }
while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) { while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) {
fwrite($targetHandle, $data); fwrite($targetHandle, $data);
} }
$this->getState()->close($sourceHandle); $this->getState()->close($sourceHandle, $this->buildUrl($source));
return true; return true;
} }

View file

@ -240,13 +240,14 @@ class NativeState {
/** /**
* @param resource $file * @param resource $file
* @param string $data * @param string $data
* @param string $path
* @param int $length * @param int $length
* @return int * @return int
*/ */
public function write($file, $data, $length = null) { public function write($file, $data, $path, $length = null) {
$result = @smbclient_write($this->state, $file, $data, $length); $result = @smbclient_write($this->state, $file, $data, $length);
$this->testResult($result, $file); $this->testResult($result, $path);
return $result; return $result;
} }
@ -275,10 +276,10 @@ class NativeState {
return $result; return $result;
} }
public function close($file) { public function close($file, $path) {
$result = @smbclient_close($this->state, $file); $result = @smbclient_close($this->state, $file);
$this->testResult($result, $file); $this->testResult($result, $path);
return $result; return $result;
} }

View file

@ -62,7 +62,7 @@ class NativeStream implements File {
public function stream_close() { public function stream_close() {
try { try {
return $this->state->close($this->handle); return $this->state->close($this->handle, $this->url);
} catch (\Exception $e) { } catch (\Exception $e) {
return false; return false;
} }
@ -114,7 +114,7 @@ class NativeStream implements File {
} }
public function stream_write($data) { public function stream_write($data) {
return $this->state->write($this->handle, $data); return $this->state->write($this->handle, $data, $this->url);
} }
public function stream_truncate($size) { public function stream_truncate($size) {

View file

@ -61,7 +61,7 @@ class NativeWriteStream extends NativeStream {
private function flushWrite() { private function flushWrite() {
rewind($this->writeBuffer); rewind($this->writeBuffer);
$this->state->write($this->handle, stream_get_contents($this->writeBuffer)); $this->state->write($this->handle, stream_get_contents($this->writeBuffer), $this->url);
$this->writeBuffer = fopen('php://memory', 'r+'); $this->writeBuffer = fopen('php://memory', 'r+');
$this->bufferSize = 0; $this->bufferSize = 0;
} }