Merge pull request #5070 from owncloud/smb-streamwrapper-fixes

Various fixes for the streamwrapper based SMB backend
This commit is contained in:
Thomas Müller 2013-10-09 03:05:51 -07:00
commit 9637ca3ae8
3 changed files with 39 additions and 14 deletions

View File

@ -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+':

View File

@ -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);
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;
return true;
} else {
return false; //not supported
}
} else {
return false;//not supported
$this->file_put_contents($path, '');
}
}

View File

@ -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'));
}
}