summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-11-19 06:13:25 -0800
committerVincent Petry <pvince81@owncloud.com>2013-11-19 06:13:25 -0800
commit5f6f78ee0342b6afd5c1a6ad4f1866267067ff00 (patch)
treed9e08530b8d4885a5ee9ac9af3891ba75e563da6
parentb55a66187c4abed63218460b675d555f82ab9142 (diff)
parent5b6d1d79d06e404ce4a52f75393a98f52769da48 (diff)
downloadnextcloud-server-5f6f78ee0342b6afd5c1a6ad4f1866267067ff00.tar.gz
nextcloud-server-5f6f78ee0342b6afd5c1a6ad4f1866267067ff00.zip
Merge pull request #5878 from owncloud/extstorage-smb
[SMB] Fix stat and unlink
-rw-r--r--apps/files/js/filelist.js12
-rw-r--r--apps/files_external/lib/smb.php19
-rw-r--r--apps/files_external/tests/smbfunctions.php41
-rw-r--r--tests/lib/files/storage/storage.php16
4 files changed, 84 insertions, 4 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index f20d9429271..5cab0707bda 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -569,8 +569,18 @@ var FileList={
FileList.updateEmptyContent();
Files.updateStorageStatistics();
} else {
+ if (result.status === 'error' && result.data.message) {
+ OC.Notification.show(result.data.message);
+ }
+ else {
+ OC.Notification.show(t('files', 'Error deleting file.'));
+ }
+ // hide notification after 10 sec
+ setTimeout(function() {
+ OC.Notification.hide();
+ }, 10000);
$.each(files,function(index,file) {
- var deleteAction = $('tr[data-file="'+files[i]+'"]').children("td.date").children(".action.delete");
+ var deleteAction = $('tr[data-file="' + file + '"] .action.delete');
deleteAction.removeClass('progress-icon').addClass('delete-icon');
});
}
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index ecd4dae0484..5bff597fdca 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -47,8 +47,13 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
public function constructUrl($path) {
if (substr($path, -1)=='/') {
- $path=substr($path, 0, -1);
+ $path = substr($path, 0, -1);
}
+ if (substr($path, 0, 1)=='/') {
+ $path = substr($path, 1);
+ }
+ // remove trailing dots which some versions of samba don't seem to like
+ $path = rtrim($path, '.');
$path = urlencode($path);
$user = urlencode($this->user);
$pass = urlencode($this->password);
@@ -77,6 +82,18 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
}
/**
+ * Unlinks file
+ * @param string @path
+ */
+ public function unlink($path) {
+ unlink($this->constructUrl($path));
+ clearstatcache();
+ // smb4php still returns false even on success so
+ // check here whether file was really deleted
+ return !file_exists($path);
+ }
+
+ /**
* check if a file or folder has been updated since $time
* @param string $path
* @param int $time
diff --git a/apps/files_external/tests/smbfunctions.php b/apps/files_external/tests/smbfunctions.php
new file mode 100644
index 00000000000..749906d0136
--- /dev/null
+++ b/apps/files_external/tests/smbfunctions.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright (c) 2013 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Storage;
+
+class SMBFunctions extends \PHPUnit_Framework_TestCase {
+
+ public function setUp() {
+ $id = uniqid();
+ // dummy config
+ $this->config = array(
+ 'run'=>false,
+ 'user'=>'test',
+ 'password'=>'testpassword',
+ 'host'=>'smbhost',
+ 'share'=>'/sharename',
+ 'root'=>'/rootdir/',
+ );
+
+ $this->instance = new \OC\Files\Storage\SMB($this->config);
+ }
+
+ public function tearDown() {
+ }
+
+ public function testGetId() {
+ $this->assertEquals('smb::test@smbhost//sharename//rootdir/', $this->instance->getId());
+ }
+
+ public function testConstructUrl() {
+ $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc", $this->instance->constructUrl('/abc'));
+ $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc", $this->instance->constructUrl('/abc/'));
+ $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc%2F", $this->instance->constructUrl('/abc/.'));
+ $this->assertEquals("smb://test:testpassword@smbhost/sharename/rootdir/abc%2Fdef", $this->instance->constructUrl('/abc/def'));
+ }
+}
diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php
index f72a5276db5..6c433e95475 100644
--- a/tests/lib/files/storage/storage.php
+++ b/tests/lib/files/storage/storage.php
@@ -182,8 +182,9 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->instance->hasUpdated('/lorem.txt', $ctimeStart - 5));
$this->assertTrue($this->instance->hasUpdated('/', $ctimeStart - 5));
- $this->assertTrue(($ctimeStart - 5) <= $mTime);
- $this->assertTrue($mTime <= ($ctimeEnd + 1));
+ // check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1)
+ $this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime);
+ $this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime);
$this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt'));
$stat = $this->instance->stat('/lorem.txt');
@@ -202,6 +203,17 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5));
}
+ public function testUnlink() {
+ $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
+ $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
+
+ $this->assertTrue($this->instance->file_exists('/lorem.txt'));
+
+ $this->assertTrue($this->instance->unlink('/lorem.txt'));
+
+ $this->assertFalse($this->instance->file_exists('/lorem.txt'));
+ }
+
public function testFOpen() {
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';