diff --git a/src/Native/NativeShare.php b/src/Native/NativeShare.php index bc734e3..93b9cf4 100644 --- a/src/Native/NativeShare.php +++ b/src/Native/NativeShare.php @@ -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); } diff --git a/src/Wrapped/Share.php b/src/Wrapped/Share.php index 4a21e99..dec9c31 100644 --- a/src/Wrapped/Share.php +++ b/src/Wrapped/Share.php @@ -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