diff options
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/NativeShare.php')
-rw-r--r-- | apps/files_external/3rdparty/icewind/smb/src/NativeShare.php | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php index 1f1d225c00a..27d975514a3 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeShare.php @@ -7,6 +7,9 @@ namespace Icewind\SMB; +use Icewind\SMB\Exception\InvalidPathException; +use Icewind\SMB\Exception\InvalidResourceException; + class NativeShare extends AbstractShare { /** * @var Server $server @@ -193,11 +196,30 @@ class NativeShare extends AbstractShare { * * @throws \Icewind\SMB\Exception\NotFoundException * @throws \Icewind\SMB\Exception\InvalidTypeException + * @throws \Icewind\SMB\Exception\InvalidPathException + * @throws \Icewind\SMB\Exception\InvalidResourceException */ public function get($source, $target) { + if (!$target) { + throw new InvalidPathException('Invalid target path: Filename cannot be empty'); + } + $targetHandle = @fopen($target, 'wb'); + if (!$targetHandle) { + $error = error_get_last(); + if (is_array($error)) { + $reason = $error['message']; + } else { + $reason = 'Unknown error'; + } + throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason); + } + $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); @@ -217,8 +239,9 @@ class NativeShare extends AbstractShare { */ public function read($source) { $this->connect(); - $handle = $this->state->open($this->buildUrl($source), 'r'); - return NativeStream::wrap($this->state, $handle, 'r'); + $url = $this->buildUrl($source); + $handle = $this->state->open($url, 'r'); + return NativeStream::wrap($this->state, $handle, 'r', $url); } /** @@ -232,8 +255,9 @@ class NativeShare extends AbstractShare { */ public function write($source) { $this->connect(); - $handle = $this->state->create($this->buildUrl($source)); - return NativeStream::wrap($this->state, $handle, 'w'); + $url = $this->buildUrl($source); + $handle = $this->state->create($url); + return NativeStream::wrap($this->state, $handle, 'w', $url); } /** |