mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 09:14:06 +02:00
Move Exceptions to their own namespace
This commit is contained in:
parent
5ab73b1afd
commit
5c57d2d094
22 changed files with 233 additions and 123 deletions
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
use Icewind\SMB\Exception\AuthenticationException;
|
||||
use Icewind\SMB\Exception\ConnectionException;
|
||||
use Icewind\SMB\Exception\InvalidHostException;
|
||||
|
||||
class Connection extends RawConnection {
|
||||
const DELIMITER = 'smb:';
|
||||
|
||||
|
|
@ -22,12 +26,12 @@ class Connection extends RawConnection {
|
|||
/**
|
||||
* get all unprocessed output from smbclient until the next prompt
|
||||
*
|
||||
* @throws ConnectionError
|
||||
* @throws ConnectionException
|
||||
* @return string
|
||||
*/
|
||||
public function read() {
|
||||
if (!$this->isValid()) {
|
||||
throw new ConnectionError();
|
||||
throw new ConnectionException();
|
||||
}
|
||||
$line = $this->readLine(); //first line is prompt
|
||||
$this->checkConnectionError($line);
|
||||
|
|
|
|||
|
|
@ -7,43 +7,6 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
class Exception extends \Exception {
|
||||
}
|
||||
|
||||
class ConnectException extends Exception {
|
||||
}
|
||||
|
||||
class ConnectionError extends ConnectException {
|
||||
}
|
||||
|
||||
class AuthenticationException extends ConnectException {
|
||||
}
|
||||
|
||||
class InvalidHostException extends ConnectException {
|
||||
}
|
||||
|
||||
class AccessDeniedException extends ConnectException {
|
||||
}
|
||||
|
||||
class InvalidRequestException extends Exception {
|
||||
}
|
||||
|
||||
class NotFoundException extends InvalidRequestException {
|
||||
}
|
||||
|
||||
class AlreadyExistsException extends InvalidRequestException {
|
||||
}
|
||||
|
||||
class NotEmptyException extends InvalidRequestException {
|
||||
}
|
||||
|
||||
class InvalidTypeException extends InvalidRequestException {
|
||||
}
|
||||
|
||||
class ForbiddenException extends InvalidRequestException {
|
||||
}
|
||||
|
||||
|
||||
class ErrorCodes {
|
||||
/**
|
||||
* connection errors
|
||||
|
|
|
|||
10
src/Exception/AccessDeniedException.php
Normal file
10
src/Exception/AccessDeniedException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 AccessDeniedException extends ConnectException {}
|
||||
10
src/Exception/AlreadyExistsException.php
Normal file
10
src/Exception/AlreadyExistsException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 AlreadyExistsException extends InvalidRequestException {}
|
||||
10
src/Exception/AuthenticationException.php
Normal file
10
src/Exception/AuthenticationException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 AuthenticationException extends ConnectException{}
|
||||
10
src/Exception/ConnectException.php
Normal file
10
src/Exception/ConnectException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 ConnectException extends Exception {}
|
||||
10
src/Exception/ConnectionException.php
Normal file
10
src/Exception/ConnectionException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 ConnectionException extends ConnectException {}
|
||||
10
src/Exception/Exception.php
Normal file
10
src/Exception/Exception.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 Exception extends \Exception {}
|
||||
10
src/Exception/ForbiddenException.php
Normal file
10
src/Exception/ForbiddenException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 ForbiddenException extends InvalidRequestException {}
|
||||
10
src/Exception/InvalidHostException.php
Normal file
10
src/Exception/InvalidHostException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 InvalidHostException extends ConnectException {}
|
||||
10
src/Exception/InvalidRequestException.php
Normal file
10
src/Exception/InvalidRequestException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 InvalidRequestException extends Exception {}
|
||||
10
src/Exception/InvalidTypeException.php
Normal file
10
src/Exception/InvalidTypeException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 InvalidTypeException extends InvalidRequestException {}
|
||||
10
src/Exception/NotEmptyException.php
Normal file
10
src/Exception/NotEmptyException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 NotEmptyException extends InvalidRequestException {}
|
||||
10
src/Exception/NotFoundException.php
Normal file
10
src/Exception/NotFoundException.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?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 NotFoundException extends InvalidRequestException {}
|
||||
|
|
@ -34,8 +34,8 @@ class NativeServer extends Server {
|
|||
|
||||
/**
|
||||
* @return \Icewind\SMB\IShare[]
|
||||
* @throws \Icewind\SMB\AuthenticationException
|
||||
* @throws \Icewind\SMB\InvalidHostException
|
||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function listShares() {
|
||||
$this->connect();
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
require_once 'ErrorCodes.php';
|
||||
|
||||
class NativeShare implements IShare {
|
||||
/**
|
||||
* @var Server $server
|
||||
|
|
@ -36,9 +34,9 @@ class NativeShare implements IShare {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \Icewind\SMB\ConnectionError
|
||||
* @throws \Icewind\SMB\AuthenticationException
|
||||
* @throws \Icewind\SMB\InvalidHostException
|
||||
* @throws \Icewind\SMB\Exception\ConnectionException
|
||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
protected function connect() {
|
||||
if ($this->state and $this->state instanceof NativeShare) {
|
||||
|
|
@ -63,7 +61,7 @@ class NativeShare implements IShare {
|
|||
}
|
||||
|
||||
private function buildUrl($path) {
|
||||
$url = 'smb://' . $this->server->getHost() . '/' . $this->name;
|
||||
$url = sprintf('smb://%s/%s', $this->server->getHost(), $this->name);
|
||||
if ($path) {
|
||||
$path = trim($path, '/');
|
||||
$url .= '/' . $path;
|
||||
|
|
@ -77,8 +75,8 @@ class NativeShare implements IShare {
|
|||
* @param string $path
|
||||
* @return \Icewind\SMB\IFileInfo[]
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function dir($path) {
|
||||
$this->connect();
|
||||
|
|
@ -115,8 +113,8 @@ class NativeShare implements IShare {
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\AlreadyExistsException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\AlreadyExistsException
|
||||
*/
|
||||
public function mkdir($path) {
|
||||
$this->connect();
|
||||
|
|
@ -129,8 +127,8 @@ class NativeShare implements IShare {
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function rmdir($path) {
|
||||
$this->connect();
|
||||
|
|
@ -143,8 +141,8 @@ class NativeShare implements IShare {
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function del($path) {
|
||||
return $this->state->unlink($this->buildUrl($path));
|
||||
|
|
@ -157,8 +155,8 @@ class NativeShare implements IShare {
|
|||
* @param string $to
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\AlreadyExistsException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\AlreadyExistsException
|
||||
*/
|
||||
public function rename($from, $to) {
|
||||
$this->connect();
|
||||
|
|
@ -172,8 +170,8 @@ class NativeShare implements IShare {
|
|||
* @param string $target remove file
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function put($source, $target) {
|
||||
$this->connect();
|
||||
|
|
@ -195,8 +193,8 @@ class NativeShare implements IShare {
|
|||
* @param string $target local file
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function get($source, $target) {
|
||||
$this->connect();
|
||||
|
|
@ -216,8 +214,8 @@ class NativeShare implements IShare {
|
|||
* @param string $source
|
||||
* @return resource a read only stream with the contents of the remote file
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function read($source) {
|
||||
$this->connect();
|
||||
|
|
@ -231,8 +229,8 @@ class NativeShare implements IShare {
|
|||
* @param string $source
|
||||
* @return resource a read only stream with the contents of the remote file
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function write($source) {
|
||||
$this->connect();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
require_once 'ErrorCodes.php';
|
||||
use Icewind\SMB\Exception\AlreadyExistsException;
|
||||
use Icewind\SMB\Exception\Exception;
|
||||
use Icewind\SMB\Exception\ForbiddenException;
|
||||
use Icewind\SMB\Exception\InvalidTypeException;
|
||||
use Icewind\SMB\Exception\NotFoundException;
|
||||
|
||||
/**
|
||||
* Low level wrapper for libsmbclient-php for error handling
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
use Icewind\SMB\Exception\ConnectionException;
|
||||
|
||||
class RawConnection {
|
||||
/**
|
||||
* @var resource[] $pipes
|
||||
|
|
@ -37,7 +39,7 @@ class RawConnection {
|
|||
));
|
||||
$this->process = proc_open($command, $descriptorSpec, $this->pipes, '/', $env);
|
||||
if (!$this->isValid()) {
|
||||
throw new ConnectionError();
|
||||
throw new ConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
use Icewind\SMB\Exception\AuthenticationException;
|
||||
use Icewind\SMB\Exception\InvalidHostException;
|
||||
|
||||
class Server {
|
||||
const CLIENT = 'smbclient';
|
||||
const LOCALE = 'en_US.UTF-8';
|
||||
|
|
@ -77,8 +80,8 @@ class Server {
|
|||
/**
|
||||
* @return \Icewind\SMB\IShare[]
|
||||
*
|
||||
* @throws \Icewind\SMB\AuthenticationException
|
||||
* @throws \Icewind\SMB\InvalidHostException
|
||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function listShares() {
|
||||
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
|
||||
|
|
|
|||
|
|
@ -7,6 +7,13 @@
|
|||
|
||||
namespace Icewind\SMB;
|
||||
|
||||
use Icewind\SMB\Exception\AccessDeniedException;
|
||||
use Icewind\SMB\Exception\AlreadyExistsException;
|
||||
use Icewind\SMB\Exception\ConnectionException;
|
||||
use Icewind\SMB\Exception\Exception;
|
||||
use Icewind\SMB\Exception\InvalidTypeException;
|
||||
use Icewind\SMB\Exception\NotEmptyException;
|
||||
use Icewind\SMB\Exception\NotFoundException;
|
||||
use Icewind\Streams\CallbackWrapper;
|
||||
|
||||
class Share implements IShare {
|
||||
|
|
@ -37,20 +44,23 @@ class Share implements IShare {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws \Icewind\SMB\ConnectionError
|
||||
* @throws \Icewind\SMB\AuthenticationException
|
||||
* @throws \Icewind\SMB\InvalidHostException
|
||||
* @throws \Icewind\SMB\Exception\ConnectionError
|
||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
protected function connect() {
|
||||
if ($this->connection and $this->connection->isValid()) {
|
||||
return;
|
||||
}
|
||||
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
|
||||
' //' . $this->server->getHost() . '/' . $this->name;
|
||||
$command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s',
|
||||
Server::CLIENT,
|
||||
$this->server->getHost(),
|
||||
$this->name
|
||||
);
|
||||
$this->connection = new Connection($command);
|
||||
$this->connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
||||
if (!$this->connection->isValid()) {
|
||||
throw new ConnectionError();
|
||||
throw new ConnectionException();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,8 +93,8 @@ class Share implements IShare {
|
|||
* @param $path
|
||||
* @return \Icewind\SMB\IFileInfo[]
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function dir($path) {
|
||||
$escapedPath = $this->escapePath($path);
|
||||
|
|
@ -146,8 +156,8 @@ class Share implements IShare {
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\AlreadyExistsException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\AlreadyExistsException
|
||||
*/
|
||||
public function mkdir($path) {
|
||||
return $this->simpleCommand('mkdir', $path);
|
||||
|
|
@ -159,8 +169,8 @@ class Share implements IShare {
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function rmdir($path) {
|
||||
return $this->simpleCommand('rmdir', $path);
|
||||
|
|
@ -172,8 +182,8 @@ class Share implements IShare {
|
|||
* @param string $path
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function del($path) {
|
||||
//del return a file not found error when trying to delete a folder
|
||||
|
|
@ -200,8 +210,8 @@ class Share implements IShare {
|
|||
* @param string $to
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\AlreadyExistsException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\AlreadyExistsException
|
||||
*/
|
||||
public function rename($from, $to) {
|
||||
$path1 = $this->escapePath($from);
|
||||
|
|
@ -218,8 +228,8 @@ class Share implements IShare {
|
|||
* @param string $target remove file
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function put($source, $target) {
|
||||
$path1 = $this->escapeLocalPath($source); //first path is local, needs different escaping
|
||||
|
|
@ -235,8 +245,8 @@ class Share implements IShare {
|
|||
* @param string $target local file
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function get($source, $target) {
|
||||
$path1 = $this->escapePath($source);
|
||||
|
|
@ -251,8 +261,8 @@ class Share implements IShare {
|
|||
* @param string $source
|
||||
* @return resource a read only stream with the contents of the remote file
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function read($source) {
|
||||
$source = $this->escapePath($source);
|
||||
|
|
@ -260,9 +270,12 @@ class Share implements IShare {
|
|||
$source = str_replace('\'', '\'"\'"\'', $source);
|
||||
// since returned stream is closed by the caller we need to create a new instance
|
||||
// since we can't re-use the same file descriptor over multiple calls
|
||||
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
|
||||
' //' . $this->server->getHost() . '/' . $this->name
|
||||
. ' -c \'get ' . $source . ' /proc/self/fd/5\'';
|
||||
$command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s -c \'get %s /proc/self/fd/5\'',
|
||||
Server::CLIENT,
|
||||
$this->server->getHost(),
|
||||
$this->name,
|
||||
$source
|
||||
);
|
||||
$connection = new Connection($command);
|
||||
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
||||
$fh = $connection->getFileOutputStream();
|
||||
|
|
@ -276,8 +289,8 @@ class Share implements IShare {
|
|||
* @param string $target
|
||||
* @return resource a write only stream to upload a remote file
|
||||
*
|
||||
* @throws \Icewind\SMB\NotFoundException
|
||||
* @throws \Icewind\SMB\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function write($target) {
|
||||
$target = $this->escapePath($target);
|
||||
|
|
@ -285,9 +298,12 @@ class Share implements IShare {
|
|||
$target = str_replace('\'', '\'"\'"\'', $target);
|
||||
// since returned stream is closed by the caller we need to create a new instance
|
||||
// since we can't re-use the same file descriptor over multiple calls
|
||||
$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
|
||||
' //' . $this->server->getHost() . '/' . $this->name
|
||||
. ' -c \'put /proc/self/fd/4 ' . $target . '\'';
|
||||
$command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s -c \'put /proc/self/fd/4 %s\'',
|
||||
Server::CLIENT,
|
||||
$this->server->getHost(),
|
||||
$this->name,
|
||||
$target
|
||||
);
|
||||
$connection = new RawConnection($command);
|
||||
$connection->writeAuthentication($this->server->getUser(), $this->server->getPassword());
|
||||
$fh = $connection->getFileInputStream();
|
||||
|
|
@ -368,11 +384,11 @@ class Share implements IShare {
|
|||
* @param $lines
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @throws AlreadyExistsException
|
||||
* @throws AccessDeniedException
|
||||
* @throws NotEmptyException
|
||||
* @throws InvalidTypeException
|
||||
* @throws \Exception
|
||||
* @throws \Icewind\SMB\Exception\AlreadyExistsException
|
||||
* @throws \Icewind\SMB\Exception\AccessDeniedException
|
||||
* @throws \Icewind\SMB\Exception\NotEmptyException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
* @throws \Icewind\SMB\Exception\Exception
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseOutput($lines) {
|
||||
|
|
|
|||
|
|
@ -203,28 +203,28 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testCreateFolderInNonExistingFolder() {
|
||||
$this->share->mkdir($this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRemoveFolderInNonExistingFolder() {
|
||||
$this->share->rmdir($this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRemoveNonExistingFolder() {
|
||||
$this->share->rmdir($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\AlreadyExistsException
|
||||
* @expectedException \Icewind\SMB\Exception\AlreadyExistsException
|
||||
*/
|
||||
public function testCreateExistingFolder() {
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
|
|
@ -233,7 +233,7 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\InvalidTypeException
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testCreateFileExistingFolder() {
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
|
|
@ -242,28 +242,28 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testCreateFileInNonExistingFolder() {
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testTestRemoveNonExistingFile() {
|
||||
$this->share->del($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testDownloadNonExistingFile() {
|
||||
$this->share->get($this->root . '/foo', '/dev/null');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\InvalidTypeException
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testDownloadFolder() {
|
||||
$this->share->mkdir($this->root . '/foobar');
|
||||
|
|
@ -272,7 +272,7 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\InvalidTypeException
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testDelFolder() {
|
||||
$this->share->mkdir($this->root . '/foobar');
|
||||
|
|
@ -281,7 +281,7 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\InvalidTypeException
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testRmdirFile() {
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foobar');
|
||||
|
|
@ -290,28 +290,28 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testDirNonExisting() {
|
||||
$this->share->dir('/foobar/asd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRmDirNonExisting() {
|
||||
$this->share->rmdir('/foobar/asd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRenameNonExisting() {
|
||||
$this->share->rename('/foobar/asd', '/foobar/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRenameTargetNonExisting() {
|
||||
$txt= $this->getTextFile();
|
||||
|
|
@ -405,7 +405,7 @@ abstract class AbstractShare extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\NotFoundException
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testStatNonExisting() {
|
||||
$this->share->stat($this->root . '/fo.txt');
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class Server extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\AuthenticationException
|
||||
* @expectedException \Icewind\SMB\Exception\AuthenticationException
|
||||
*/
|
||||
public function testWrongUserName() {
|
||||
$this->markTestSkipped('This fails for no reason on travis');
|
||||
|
|
@ -40,7 +40,7 @@ class Server extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\AuthenticationException
|
||||
* @expectedException \Icewind\SMB\Exception\AuthenticationException
|
||||
*/
|
||||
public function testWrongPassword() {
|
||||
$server = new \Icewind\SMB\Server($this->config->host, $this->config->user, uniqid());
|
||||
|
|
@ -48,7 +48,7 @@ class Server extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\InvalidHostException
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function testWrongHost() {
|
||||
$server = new \Icewind\SMB\Server(uniqid(), $this->config->user, $this->config->password);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue