diff options
author | Robin Appelman <robin@icewind.nl> | 2019-02-06 17:36:06 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2019-02-06 18:08:58 +0300 |
commit | 89b0d28cb44e556159bdb7e5bd99dfb6f7b54880 (patch) | |
tree | 08185e118dae22a8e14232ede599fdc4843f6ccd /apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php | |
parent | 49ae3a3daa3ea479902386792b34359cbc8a8fdf (diff) |
update icewind/smb to 3.1.0
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php')
-rw-r--r-- | apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php index 130a5a070ff..1a33f4b0d36 100644 --- a/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php +++ b/apps/files_external/3rdparty/icewind/smb/src/Native/NativeShare.php @@ -53,7 +53,7 @@ class NativeShare extends AbstractShare { } $this->state = new NativeState(); - $this->state->init($this->server->getAuth()); + $this->state->init($this->server->getAuth(), $this->server->getOptions()); return $this->state; } @@ -87,13 +87,16 @@ class NativeShare extends AbstractShare { * @throws \Icewind\SMB\Exception\InvalidTypeException */ public function dir($path) { - $files = array(); + $files = []; $dh = $this->getState()->opendir($this->buildUrl($path)); while ($file = $this->getState()->readdir($dh)) { $name = $file['name']; if ($name !== '.' and $name !== '..') { - $files [] = new NativeFileInfo($this, $path . '/' . $name, $name); + $fullPath = $path . '/' . $name; + $files [] = new NativeFileInfo($this, $fullPath, $name, function () use ($fullPath) { + return $this->getStat($fullPath); + }); } } @@ -106,10 +109,27 @@ class NativeShare extends AbstractShare { * @return \Icewind\SMB\IFileInfo */ public function stat($path) { - return new NativeFileInfo($this, $path, basename($path), $this->getStat($path)); + return new NativeFileInfo($this, $path, self::mb_basename($path), $this->getStat($path)); } - public function getStat($path) { + /** + * Multibyte unicode safe version of basename() + * + * @param string $path + * @link http://php.net/manual/en/function.basename.php#121405 + * @return string + */ + protected static function mb_basename($path) { + if (preg_match('@^.*[\\\\/]([^\\\\/]+)$@s', $path, $matches)) { + return $matches[1]; + } elseif (preg_match('@^([^\\\\/]+)$@s', $path, $matches)) { + return $matches[1]; + } + + return ''; + } + + private function getStat($path) { return $this->getState()->stat($this->buildUrl($path)); } @@ -228,7 +248,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 +263,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 @@ -258,6 +279,21 @@ class NativeShare extends AbstractShare { } /** + * 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 * * @param string $path @@ -269,15 +305,14 @@ 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 - * @param mixed $value - * @return string the attribute value + * @param string|int $value + * @return mixed the attribute value */ public function setAttribute($path, $attribute, $value) { - if ($attribute === 'system.dos_attr.mode' and is_int($value)) { $value = '0x' . dechex($value); } @@ -286,6 +321,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 @@ -295,16 +332,19 @@ class NativeShare extends AbstractShare { } /** + * Start smb notify listener + * Note: This is a blocking call + * * @param string $path * @return INotifyHandler */ public function notify($path) { - // php-smbclient does support notify (https://github.com/eduardok/libsmbclient-php/issues/29) + // php-smbclient does not support notify (https://github.com/eduardok/libsmbclient-php/issues/29) // so we use the smbclient based backend for this if (!Server::available($this->server->getSystem())) { throw new DependencyException('smbclient not found in path for notify command'); } - $share = new Share($this->server, $this->getName()); + $share = new Share($this->server, $this->getName(), $this->server->getSystem()); return $share->notify($path); } |