Implemented IShare::append(), leave ::write() due backwards compatibility

This commit is contained in:
Robin Appelman 2018-08-28 16:21:15 +02:00
commit 59519bad2c
5 changed files with 79 additions and 5 deletions

View file

@ -52,6 +52,7 @@ interface IShare {
/**
* Open a writable stream to a remote file
* Note: This method will truncate the file to 0bytes
*
* @param string $target
* @return resource a write only stream to upload a remote file
@ -61,6 +62,18 @@ interface IShare {
*/
public function write($target);
/**
* Open a writable stream to a remote file and set the cursor to the end of the file
*
* @param string $target
* @return resource a write only stream to upload a remote file
*
* @throws \Icewind\SMB\Exception\NotFoundException
* @throws \Icewind\SMB\Exception\InvalidTypeException
* @throws \Icewind\SMB\Exception\InvalidRequestException
*/
public function append($target);
/**
* Rename a remote file
*

View file

@ -109,6 +109,12 @@ class NativeShare extends AbstractShare {
return new NativeFileInfo($this, $path, basename($path), $this->getStat($path));
}
/**
* Get fstat
*
* @param string $path
* @return array
*/
public function getStat($path) {
return $this->getState()->stat($this->buildUrl($path));
}
@ -228,7 +234,7 @@ class NativeShare extends AbstractShare {
}
/**
* Open a readable stream top a remote file
* Open a readable stream to a remote file
*
* @param string $source
* @return resource a read only stream with the contents of the remote file
@ -243,10 +249,11 @@ class NativeShare extends AbstractShare {
}
/**
* Open a readable stream top a remote file
* Open a writeable stream to a remote file
* Note: This method will truncate the file to 0bytes first
*
* @param string $source
* @return resource a read only stream with the contents of the remote file
* @return resource a writeable stream
*
* @throws \Icewind\SMB\Exception\NotFoundException
* @throws \Icewind\SMB\Exception\InvalidTypeException
@ -257,6 +264,21 @@ class NativeShare extends AbstractShare {
return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url);
}
/**
* Open a writeable stream and set the cursor to the end of the stream
*
* @param string $source
* @return resource a writeable stream
*
* @throws \Icewind\SMB\Exception\NotFoundException
* @throws \Icewind\SMB\Exception\InvalidTypeException
*/
public function append($source) {
$url = $this->buildUrl($source);
$handle = $this->getState()->open($url, "a");
return NativeWriteStream::wrap($this->getState(), $handle, "a", $url);
}
/**
* Get extended attributes for the path
*
@ -269,7 +291,7 @@ class NativeShare extends AbstractShare {
}
/**
* Get extended attributes for the path
* Set extended attributes for the given path
*
* @param string $path
* @param string $attribute attribute to get the info
@ -285,6 +307,8 @@ class NativeShare extends AbstractShare {
}
/**
* Set DOS comaptible node mode
*
* @param string $path
* @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL
* @return mixed
@ -294,6 +318,9 @@ class NativeShare extends AbstractShare {
}
/**
* Start smb notify listener
* Note: This is a blocking call
*
* @param string $path
* @return INotifyHandler
*/

View file

@ -13,6 +13,7 @@ use Icewind\SMB\Exception\DependencyException;
use Icewind\SMB\Exception\FileInUseException;
use Icewind\SMB\Exception\InvalidTypeException;
use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\Exception\InvalidRequestException;
use Icewind\SMB\IFileInfo;
use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IServer;
@ -342,6 +343,17 @@ class Share extends AbstractShare {
});
}
/**
* Append on wrapped smbclient not supported
*
* @param string $source
*
* @throws \Icewind\SMB\Exception\InvalidRequestException
*/
public function append($source) {
throw new InvalidRequestException("Not supported, use Icewind\SMB\Native\NativeShare");
}
/**
* @param string $path
* @param int $mode a combination of FileInfo::MODE_READONLY, FileInfo::MODE_ARCHIVE, FileInfo::MODE_SYSTEM and FileInfo::MODE_HIDDEN, FileInfo::NORMAL