mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
optional truncate
This commit is contained in:
parent
e6c7a6763b
commit
7e49f35ae3
2 changed files with 17 additions and 4 deletions
|
|
@ -265,17 +265,24 @@ class NativeShare extends AbstractShare {
|
|||
|
||||
/**
|
||||
* Open a writeable stream to a remote file
|
||||
* Note: This method will truncate the file to 0bytes first
|
||||
* Note: The default will truncate the file to 0 bytes.
|
||||
*
|
||||
* @param string $source
|
||||
* @param bool $truncate
|
||||
* @return resource a writeable stream
|
||||
*
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function write($source) {
|
||||
public function write($source, $truncate=true) {
|
||||
$url = $this->buildUrl($source);
|
||||
$handle = $this->getState()->create($url);
|
||||
|
||||
if($truncate === true) {
|
||||
$handle = $this->getState()->create($url);
|
||||
} else {
|
||||
$handle = $this->getState()->open($url, 'c');
|
||||
}
|
||||
|
||||
return NativeWriteStream::wrap($this->getState(), $handle, 'w', $url);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -326,12 +326,18 @@ class Share extends AbstractShare {
|
|||
* Open a writable stream to a remote file
|
||||
*
|
||||
* @param string $target
|
||||
* @param bool $truncate
|
||||
* @return resource a write only stream to upload a remote file
|
||||
*
|
||||
* @throws \Icewind\SMB\Exception\DependencyException
|
||||
* @throws \Icewind\SMB\Exception\NotFoundException
|
||||
* @throws \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function write($target) {
|
||||
public function write($target, $truncate=true) {
|
||||
if($truncate === false) {
|
||||
throw new DependencyException('truncate required by smbclient, use php-libsmbclient instead');
|
||||
}
|
||||
|
||||
$target = $this->escapePath($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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue