summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-10-09 03:05:51 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-10-09 03:05:51 -0700
commit9637ca3ae839b11b85e2c26e49d728429aee2834 (patch)
tree674ce14f14ab374cd414e1601a0a2f7be417cc62
parentb4df4cc61d897703176b0ca5cad7fa687ddd059b (diff)
parent51c34777c4accae634b7877fac970fd2a2e2550c (diff)
downloadnextcloud-server-9637ca3ae839b11b85e2c26e49d728429aee2834.tar.gz
nextcloud-server-9637ca3ae839b11b85e2c26e49d728429aee2834.zip
Merge pull request #5070 from owncloud/smb-streamwrapper-fixes
Various fixes for the streamwrapper based SMB backend
-rw-r--r--apps/files_external/3rdparty/smb4php/smb.php10
-rw-r--r--apps/files_external/lib/streamwrapper.php36
-rw-r--r--apps/files_external/tests/smb.php9
3 files changed, 40 insertions, 15 deletions
diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php
index e7d1dfa09fe..e91b0a59581 100644
--- a/apps/files_external/3rdparty/smb4php/smb.php
+++ b/apps/files_external/3rdparty/smb4php/smb.php
@@ -181,6 +181,8 @@ class smb {
return false;
}elseif(substr($regs[0],0,31)=='NT_STATUS_OBJECT_PATH_NOT_FOUND'){
return false;
+ }elseif(substr($regs[0],0,31)=='NT_STATUS_OBJECT_NAME_NOT_FOUND'){
+ return false;
}elseif(substr($regs[0],0,29)=='NT_STATUS_FILE_IS_A_DIRECTORY'){
return false;
}
@@ -305,7 +307,8 @@ class smb {
trigger_error('rename(): error in URL', E_USER_ERROR);
}
smb::clearstatcache ($url_from);
- return smb::execute ('rename "'.$from['path'].'" "'.$to['path'].'"', $to);
+ $result = smb::execute ('rename "'.$from['path'].'" "'.$to['path'].'"', $to);
+ return $result !== false;
}
function mkdir ($url, $mode, $options) {
@@ -430,7 +433,10 @@ class smb_stream_wrapper extends smb {
case 'rb':
case 'a':
case 'a+': $this->tmpfile = tempnam('/tmp', 'smb.down.');
- smb::execute ('get "'.$pu['path'].'" "'.$this->tmpfile.'"', $pu);
+ $result = smb::execute ('get "'.$pu['path'].'" "'.$this->tmpfile.'"', $pu);
+ if($result === false){
+ return $result;
+ }
break;
case 'w':
case 'w+':
diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index beb4ec5605f..4a63dfb6e02 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -8,7 +8,7 @@
namespace OC\Files\Storage;
-abstract class StreamWrapper extends Common{
+abstract class StreamWrapper extends Common {
abstract public function constructUrl($path);
public function mkdir($path) {
@@ -16,7 +16,15 @@ abstract class StreamWrapper extends Common{
}
public function rmdir($path) {
- if($this->file_exists($path)) {
+ if ($this->file_exists($path)) {
+ $dh = $this->opendir($path);
+ while (($file = readdir($dh)) !== false) {
+ if ($this->is_dir($path . '/' . $file)) {
+ $this->rmdir($path . '/' . $file);
+ } else {
+ $this->unlink($path . '/' . $file);
+ }
+ }
$success = rmdir($this->constructUrl($path));
clearstatcache();
return $success;
@@ -34,11 +42,11 @@ abstract class StreamWrapper extends Common{
}
public function isReadable($path) {
- return true;//not properly supported
+ return true; //not properly supported
}
public function isUpdatable($path) {
- return true;//not properly supported
+ return true; //not properly supported
}
public function file_exists($path) {
@@ -55,15 +63,19 @@ abstract class StreamWrapper extends Common{
return fopen($this->constructUrl($path), $mode);
}
- public function touch($path, $mtime=null) {
- if(is_null($mtime)) {
- $fh = $this->fopen($path, 'a');
- fwrite($fh, '');
- fclose($fh);
-
- return true;
+ public function touch($path, $mtime = null) {
+ if ($this->file_exists($path)) {
+ if (is_null($mtime)) {
+ $fh = $this->fopen($path, 'a');
+ fwrite($fh, '');
+ fclose($fh);
+
+ return true;
+ } else {
+ return false; //not supported
+ }
} else {
- return false;//not supported
+ $this->file_put_contents($path, '');
}
}
diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php
index ca2a93c8944..0291f293fa6 100644
--- a/apps/files_external/tests/smb.php
+++ b/apps/files_external/tests/smb.php
@@ -15,7 +15,7 @@ class SMB extends Storage {
public function setUp() {
$id = uniqid();
$this->config = include('files_external/tests/config.php');
- if ( ! is_array($this->config) or ! isset($this->config['smb']) or ! $this->config['smb']['run']) {
+ if (!is_array($this->config) or !isset($this->config['smb']) or !$this->config['smb']['run']) {
$this->markTestSkipped('Samba backend not configured');
}
$this->config['smb']['root'] .= $id; //make sure we have an new empty folder to work in
@@ -28,4 +28,11 @@ class SMB extends Storage {
\OCP\Files::rmdirr($this->instance->constructUrl(''));
}
}
+
+ public function testRenameWithSpaces() {
+ $this->instance->mkdir('with spaces');
+ $result = $this->instance->rename('with spaces', 'foo bar');
+ $this->assertTrue($result);
+ $this->assertTrue($this->instance->is_dir('foo bar'));
+ }
}