Skip to content

Commit

Permalink
add proper paths to exceptions during stream close and write
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Apr 8, 2020
1 parent b2a6274 commit db50bb5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/Native/NativeShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@ public function rename($from, $to) {
*/
public function put($source, $target) {
$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)) {
$this->getState()->write($targetHandle, $data);
$this->getState()->write($targetHandle, $data, $targetUrl);
}
$this->getState()->close($targetHandle);
$this->getState()->close($targetHandle, $targetUrl);
return true;
}

Expand Down Expand Up @@ -236,14 +238,14 @@ public function get($source, $target) {
} else {
$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);
}

while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) {
fwrite($targetHandle, $data);
}
$this->getState()->close($sourceHandle);
$this->getState()->close($sourceHandle, $this->buildUrl($source));
return true;
}

Expand Down
9 changes: 5 additions & 4 deletions src/Native/NativeState.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ public function read($file, $bytes) {
/**
* @param resource $file
* @param string $data
* @param string $path
* @param int $length
* @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);

$this->testResult($result, $file);
$this->testResult($result, $path);
return $result;
}

Expand Down Expand Up @@ -275,10 +276,10 @@ public function ftruncate($file, $size) {
return $result;
}

public function close($file) {
public function close($file, $path) {
$result = @smbclient_close($this->state, $file);

$this->testResult($result, $file);
$this->testResult($result, $path);
return $result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Native/NativeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function wrap($state, $smbStream, $mode, $url) {

public function stream_close() {
try {
return $this->state->close($this->handle);
return $this->state->close($this->handle, $this->url);
} catch (\Exception $e) {
return false;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public function stream_tell() {
}

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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Native/NativeWriteStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function stream_seek($offset, $whence = SEEK_SET) {

private function flushWrite() {
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->bufferSize = 0;
}
Expand Down

0 comments on commit db50bb5

Please sign in to comment.