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
11
src/Exception/InvalidResourceException.php
Normal file
11
src/Exception/InvalidResourceException.php
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||||
|
* This file is licensed under the Licensed under the MIT license:
|
||||||
|
* http://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Icewind\SMB\Exception;
|
||||||
|
|
||||||
|
class InvalidResourceException extends Exception {
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
namespace Icewind\SMB;
|
namespace Icewind\SMB;
|
||||||
|
|
||||||
|
use Icewind\SMB\Exception\InvalidResourceException;
|
||||||
|
|
||||||
class NativeShare extends AbstractShare {
|
class NativeShare extends AbstractShare {
|
||||||
/**
|
/**
|
||||||
* @var Server $server
|
* @var Server $server
|
||||||
|
|
@ -193,11 +195,20 @@ class NativeShare extends AbstractShare {
|
||||||
*
|
*
|
||||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||||
|
* @throws \Icewind\SMB\Exception\InvalidResourceException
|
||||||
*/
|
*/
|
||||||
public function get($source, $target) {
|
public function get($source, $target) {
|
||||||
|
$targetHandle = fopen($target, 'wb');
|
||||||
|
if (!$targetHandle) {
|
||||||
|
throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing');
|
||||||
|
}
|
||||||
|
|
||||||
$this->connect();
|
$this->connect();
|
||||||
$sourceHandle = $this->state->open($this->buildUrl($source), 'r');
|
$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)) {
|
while ($data = $this->state->read($sourceHandle, 4096)) {
|
||||||
fwrite($targetHandle, $data);
|
fwrite($targetHandle, $data);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use Icewind\SMB\Exception\AccessDeniedException;
|
||||||
use Icewind\SMB\Exception\AlreadyExistsException;
|
use Icewind\SMB\Exception\AlreadyExistsException;
|
||||||
use Icewind\SMB\Exception\Exception;
|
use Icewind\SMB\Exception\Exception;
|
||||||
use Icewind\SMB\Exception\FileInUseException;
|
use Icewind\SMB\Exception\FileInUseException;
|
||||||
|
use Icewind\SMB\Exception\InvalidResourceException;
|
||||||
use Icewind\SMB\Exception\InvalidTypeException;
|
use Icewind\SMB\Exception\InvalidTypeException;
|
||||||
use Icewind\SMB\Exception\NotEmptyException;
|
use Icewind\SMB\Exception\NotEmptyException;
|
||||||
use Icewind\SMB\Exception\NotFoundException;
|
use Icewind\SMB\Exception\NotFoundException;
|
||||||
|
|
@ -42,6 +43,13 @@ class Parser {
|
||||||
$error = $part;
|
$error = $part;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notFoundMsg = 'Error opening local file ';
|
||||||
|
if (substr($output[0], 0, strlen($notFoundMsg)) === $notFoundMsg) {
|
||||||
|
$localPath = substr($output[0], strlen($notFoundMsg));
|
||||||
|
throw new InvalidResourceException('Failed opening local file "' . $localPath . '" for writing');
|
||||||
|
}
|
||||||
|
|
||||||
switch ($error) {
|
switch ($error) {
|
||||||
case ErrorCodes::PathNotFound:
|
case ErrorCodes::PathNotFound:
|
||||||
case ErrorCodes::ObjectNotFound:
|
case ErrorCodes::ObjectNotFound:
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,20 @@ abstract class AbstractShare extends TestCase {
|
||||||
unlink($targetFile);
|
unlink($targetFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Icewind\SMB\Exception\InvalidResourceException
|
||||||
|
*/
|
||||||
|
public function testGetInvalidTarget() {
|
||||||
|
$name = 'test.txt';
|
||||||
|
$text = 'dummy';
|
||||||
|
$tmpFile = $this->getTextFile($text);
|
||||||
|
|
||||||
|
$this->share->put($tmpFile, $this->root . '/' . $name);
|
||||||
|
unlink($tmpFile);
|
||||||
|
|
||||||
|
$this->share->get($this->root . '/' . $name, '/non/existing/file');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider nameProvider
|
* @dataProvider nameProvider
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue