mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
handle invalid handles in Share->get
This commit is contained in:
parent
d8105d7695
commit
1fb6581c8d
4 changed files with 45 additions and 1 deletions
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
use Icewind\SMB\Exception\InvalidResourceException;
|
||||
|
||||
class NativeShare extends AbstractShare {
|
||||
/**
|
||||
* @var Server $server
|
||||
|
|
@ -193,11 +195,20 @@ class NativeShare extends AbstractShare {
|
|||
*
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\InvalidResourceException
|
||||
*/
|
||||
public function get($source, $target) {
|
||||
$targetHandle = fopen($target, 'wb');
|
||||
if (!$targetHandle) {
|
||||
throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing');
|
||||
}
|
||||
|
||||
$this->connect();
|
||||
$sourceHandle = $this->state->open($this->buildUrl($source), 'r');
|
||||
$targetHandle = fopen($target, 'wb');
|
||||
if (!$sourceHandle) {
|
||||
fclose($targetHandle);
|
||||
throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading');
|
||||
}
|
||||
|
||||
while ($data = $this->state->read($sourceHandle, 4096)) {
|
||||
fwrite($targetHandle, $data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue