From ea6115bfaa6f8598da727dfacbcf093578149d9d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 1 Oct 2013 22:18:03 +0200 Subject: fix smb streamwrapper on non existing files --- apps/files_external/3rdparty/smb4php/smb.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php index e7d1dfa09fe..aec181a3509 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; } @@ -430,7 +432,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+': -- cgit v1.2.3 From ea566868a8c0ce7da49fceb29a9d22b46034d642 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 1 Oct 2013 22:29:33 +0200 Subject: return the correct result when doing an smb rename --- apps/files_external/3rdparty/smb4php/smb.php | 3 ++- apps/files_external/tests/smb.php | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php index aec181a3509..e91b0a59581 100644 --- a/apps/files_external/3rdparty/smb4php/smb.php +++ b/apps/files_external/3rdparty/smb4php/smb.php @@ -307,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) { diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php index ca2a93c8944..86dbd3ab88d 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,10 @@ 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); + } } -- cgit v1.2.3 From 29deef38b27f2b33eec8925cab7f6f323a35ea96 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 1 Oct 2013 22:31:22 +0200 Subject: fix using touch to create a file for smb --- apps/files_external/lib/streamwrapper.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php index beb4ec5605f..a110c006529 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,7 @@ abstract class StreamWrapper extends Common{ } public function rmdir($path) { - if($this->file_exists($path)) { + if ($this->file_exists($path)) { $success = rmdir($this->constructUrl($path)); clearstatcache(); return $success; @@ -34,11 +34,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 +55,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, ''); } } -- cgit v1.2.3 From de43515cfad858224393f5cc5bfb35c07a1820b0 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 1 Oct 2013 22:33:58 +0200 Subject: fix recursive delete for smb --- apps/files_external/lib/streamwrapper.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php index a110c006529..4a63dfb6e02 100644 --- a/apps/files_external/lib/streamwrapper.php +++ b/apps/files_external/lib/streamwrapper.php @@ -17,6 +17,14 @@ abstract class StreamWrapper extends Common { public function rmdir($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; -- cgit v1.2.3 From 51c34777c4accae634b7877fac970fd2a2e2550c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 2 Oct 2013 22:28:19 +0200 Subject: extend test case --- apps/files_external/tests/smb.php | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/smb.php index 86dbd3ab88d..0291f293fa6 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/smb.php @@ -33,5 +33,6 @@ class SMB extends Storage { $this->instance->mkdir('with spaces'); $result = $this->instance->rename('with spaces', 'foo bar'); $this->assertTrue($result); + $this->assertTrue($this->instance->is_dir('foo bar')); } } -- cgit v1.2.3