summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-05-01 12:53:49 -0300
committerGitHub <noreply@github.com>2017-05-01 12:53:49 -0300
commit3eba37ac14dd24bcfe855800b9ec90c3e65e521c (patch)
tree8464c2ed40acd6324a603d9952bd660eade8931f /apps/files_external/lib
parent7a2d817c832a87193b9658cfa561162d0a4060da (diff)
parentacb0903514f1a34480589197655281bdc1a16de9 (diff)
downloadnextcloud-server-3eba37ac14dd24bcfe855800b9ec90c3e65e521c.tar.gz
nextcloud-server-3eba37ac14dd24bcfe855800b9ec90c3e65e521c.zip
Merge pull request #4527 from nextcloud/downstream-27504
Adjust SMB permissions on the root
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/Lib/Storage/SMB.php70
1 files changed, 46 insertions, 24 deletions
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php
index cc4cd641ce5..7afdb746a98 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -31,6 +31,7 @@
namespace OCA\Files_External\Lib\Storage;
+use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\ConnectException;
use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\ForbiddenException;
@@ -90,6 +91,7 @@ class SMB extends Common implements INotifyStorage {
throw new \Exception('Invalid configuration');
}
$this->statCache = new CappedMemoryCache();
+ parent::__construct($params);
}
/**
@@ -162,10 +164,42 @@ class SMB extends Common implements INotifyStorage {
* @return array
*/
protected function formatInfo($info) {
- return array(
+ $result = [
'size' => $info->getSize(),
- 'mtime' => $info->getMTime()
- );
+ 'mtime' => $info->getMTime(),
+ ];
+ if ($info->isDirectory()) {
+ $result['type'] = 'dir';
+ } else {
+ $result['type'] = 'file';
+ }
+ return $result;
+ }
+
+ /**
+ * Rename the files. If the source or the target is the root, the rename won't happen.
+ *
+ * @param string $source the old name of the path
+ * @param string $target the new name of the path
+ * @return bool true if the rename is successful, false otherwise
+ */
+ public function rename($source, $target) {
+ if ($this->isRootDir($source) || $this->isRootDir($target)) {
+ return false;
+ }
+
+ $absoluteSource = $this->buildPath($source);
+ $absoluteTarget = $this->buildPath($target);
+ try {
+ $result = $this->share->rename($absoluteSource, $absoluteTarget);
+ } catch (AlreadyExistsException $e) {
+ $this->remove($target);
+ $result = $this->share->rename($absoluteSource, $absoluteTarget);
+ } catch (\Exception $e) {
+ return false;
+ }
+ unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
+ return $result;
}
/**
@@ -220,6 +254,10 @@ class SMB extends Common implements INotifyStorage {
* @return bool
*/
public function unlink($path) {
+ if ($this->isRootDir($path)) {
+ return false;
+ }
+
try {
if ($this->is_dir($path)) {
return $this->rmdir($path);
@@ -239,26 +277,6 @@ class SMB extends Common implements INotifyStorage {
}
/**
- * @param string $path1 the old name
- * @param string $path2 the new name
- * @return bool
- */
- public function rename($path1, $path2) {
- try {
- $this->remove($path2);
- $path1 = $this->buildPath($path1);
- $path2 = $this->buildPath($path2);
- return $this->share->rename($path1, $path2);
- } catch (NotFoundException $e) {
- return false;
- } catch (ForbiddenException $e) {
- return false;
- } catch (ConnectException $e) {
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
- }
- }
-
- /**
* check if a file or folder has been updated since $time
*
* @param string $path
@@ -266,7 +284,7 @@ class SMB extends Common implements INotifyStorage {
* @return bool
*/
public function hasUpdated($path, $time) {
- if (!$path and $this->root == '/') {
+ if (!$path and $this->root === '/') {
// mtime doesn't work for shares, but giving the nature of the backend,
// doing a full update is still just fast enough
return true;
@@ -343,6 +361,10 @@ class SMB extends Common implements INotifyStorage {
}
public function rmdir($path) {
+ if ($this->isRootDir($path)) {
+ return false;
+ }
+
try {
$this->statCache = array();
$content = $this->share->dir($this->buildPath($path));