summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2014-06-23 16:29:01 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2014-06-23 16:29:01 +0200
commit28c1a9557561319910bb86e9d04afcf6bb4bbf4f (patch)
tree3a39fbacbef3529c51aa63acb079abf79fb716b8
parent7ec53571c4b0df361aedc82204d5dba0cca1fd0b (diff)
downloadnextcloud-server-28c1a9557561319910bb86e9d04afcf6bb4bbf4f.tar.gz
nextcloud-server-28c1a9557561319910bb86e9d04afcf6bb4bbf4f.zip
use common storage test
-rw-r--r--lib/private/files/objectstore/objectstorestorage.php61
-rw-r--r--tests/lib/files/objectstore/swift.php204
2 files changed, 42 insertions, 223 deletions
diff --git a/lib/private/files/objectstore/objectstorestorage.php b/lib/private/files/objectstore/objectstorestorage.php
index 63d672c596a..16b28a61ece 100644
--- a/lib/private/files/objectstore/objectstorestorage.php
+++ b/lib/private/files/objectstore/objectstorestorage.php
@@ -20,6 +20,7 @@
namespace OC\Files\ObjectStore;
+use OC\Files\Filesystem;
use OCP\Files\ObjectStore\IObjectStore;
class ObjectStoreStorage extends \OC\Files\Storage\Common {
@@ -177,6 +178,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
}
public function stat($path) {
+ $path = $this->normalizePath($path);
return $this->getCache()->get($path);
}
@@ -200,8 +202,6 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
if ($path === '.') {
$path = '';
- } else if ($path) {
- $path .= '/';
}
try {
@@ -211,9 +211,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$files[] = $file['name'];
}
- \OC\Files\Stream\Dir::register('object' . $path, $files);
+ \OC\Files\Stream\Dir::register('objectstore' . $path . '/', $files);
- return opendir('fakedir://object' . $path);
+ return opendir('fakedir://objectstore' . $path . '/');
} catch (Exception $e) {
\OCP\Util::writeLog('objectstore', $e->getMessage(), \OCP\Util::ERROR);
return false;
@@ -285,32 +285,41 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
return (bool)$this->stat($path);
}
- public function rename($path1, $path2) {
- $path1 = $this->normalizePath($path1);
- $path2 = $this->normalizePath($path2);
- $stat1 = $this->stat($path1);
- if (is_array($stat1)) {
- $parent = $this->stat(dirname($path2));
- if (is_array($parent)) {
- $stat2 = $this->stat($path2);
- if (is_array($stat2)) {
- $this->unlink($path2);
+ public function rename($source, $target) {
+ $source = $this->normalizePath($source);
+ $target = $this->normalizePath($target);
+ $stat1 = $this->stat($source);
+ if (isset($stat1['mimetype']) && $stat1['mimetype'] === 'httpd/unix-directory') {
+ $this->remove($target);
+ $dir = $this->opendir($source);
+ $this->mkdir($target);
+ while ($file = readdir($dir)) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ if (!$this->rename($source . '/' . $file, $target . '/' . $file)) {
+ return false;
+ }
}
- $stat1['parent'] = $parent['fileid'];
- $stat1['path'] = $path2;
- $stat1['path_hash'] = md5($path2);
- $stat1['name'] = \OC_Util::basename($path2);
- $stat1['mtime'] = time();
- $stat1['etag'] = $this->getETag($path2);
- $this->getCache()->update($stat1['fileid'], $stat1);
- return true;
- } else {
- return false;
}
-
+ closedir($dir);
+ $this->remove($source);
+ return true;
} else {
- return false;
+ if (is_array($stat1)) {
+ $parent = $this->stat(dirname($target));
+ if (is_array($parent)) {
+ $this->remove($target);
+ $stat1['parent'] = $parent['fileid'];
+ $stat1['path'] = $target;
+ $stat1['path_hash'] = md5($target);
+ $stat1['name'] = \OC_Util::basename($target);
+ $stat1['mtime'] = time();
+ $stat1['etag'] = $this->getETag($target);
+ $this->getCache()->update($stat1['fileid'], $stat1);
+ return true;
+ }
+ }
}
+ return false;
}
public function getMimeType($path) {
diff --git a/tests/lib/files/objectstore/swift.php b/tests/lib/files/objectstore/swift.php
index d05af4d6587..8ac899288e6 100644
--- a/tests/lib/files/objectstore/swift.php
+++ b/tests/lib/files/objectstore/swift.php
@@ -25,17 +25,13 @@ use OC\Files\ObjectStore\Swift as ObjectStoreToTest;
use PHPUnit_Framework_TestCase;
-class Swift extends PHPUnit_Framework_TestCase {
-
- /**
- * @var \OC\Files\ObjectStore\Swift $storage
- */
- private $storage;
+//class Swift extends PHPUnit_Framework_TestCase {
+class Swift extends \Test\Files\Storage\Storage {
private $objectStorage;
-
+
public function setUp() {
-
+
\OC_App::disable('files_sharing');
\OC_App::disable('files_versions');
@@ -72,202 +68,16 @@ class Swift extends PHPUnit_Framework_TestCase {
);
$this->objectStorage = new ObjectStoreToTest($params);
$params['objectstore'] = $this->objectStorage;
- $this->storage = new ObjectStoreStorage($params);
+ $this->instance = new ObjectStoreStorage($params);
}
public function tearDown() {
- if (is_null($this->storage)) {
+ if (is_null($this->instance)) {
return;
}
$this->objectStorage->deleteContainer(true);
- $this->storage->getCache()->clear();
+ $this->instance->getCache()->clear();
//TODO how do I clear hooks?
}
-
- public function testStat () {
- $stat = $this->storage->stat('');
- $this->assertInternalType('array', $stat);
- $this->assertEquals(-1, $stat['parent']);
- $this->assertEquals('', $stat['path']);
- $this->assertEquals('', $stat['name']);
- $this->assertEquals(0, $stat['size']);
- }
- public function testMkdir () {
- $root = $this->storage->stat('');
-
- $statBefore = $this->storage->stat('someuser');
- $this->assertFalse($statBefore);
-
- $this->storage->mkdir('someuser');
- $statAfter = $this->storage->stat('someuser');
-
- $this->assertTrue(is_array($statAfter));
- $this->assertEquals($root['fileid'], $statAfter['parent']);
- $this->assertEquals('someuser', $statAfter['path']);
- $this->assertEquals('someuser', $statAfter['name']);
- $this->assertEquals(0, $statAfter['size']);
-
- }
-
- public function filesProvider() {
- return array(
- array('file.txt'),
- array(' file.txt'),
- array('file.txt '),
- array('file with space.txt'),
- array('spéciäl fìle.txt'),
- array('☠ skull and crossbones.txt'),
- array('skull and crossbones ☠ in between.txt'),
- array('💩 pile of poo.txt'),
- array('pile of 💩.txt'),
- // check if someone tries to guess type on a date string
- array('2013-04-25'),
- );
- }
- /**
- * @dataProvider filesProvider
- */
- public function testTouch ($file) {
- $root = $this->storage->stat('');
-
- $statBefore = $this->storage->stat($file);
- $this->assertFalse($statBefore);
-
- $this->assertTrue($this->storage->touch($file));
- $statAfter = $this->storage->stat($file);
-
- $this->assertTrue(is_array($statAfter));
- $this->assertEquals($root['fileid'], $statAfter['parent']);
- $this->assertEquals($file, $statAfter['path']);
- $this->assertEquals($file, $statAfter['name']);
- $this->assertEquals(0, $statAfter['size']);
-
- $this->assertFalse($this->storage->touch('non-existing/'.$file));
-
- //TODO test mtime
- //TODO test existing files
- //TODO test folders
- }
- /**
- * @dataProvider filesProvider
- */
- public function testUnlink ($file) {
- $root = $this->storage->stat('');
-
- $this->assertFalse($this->storage->unlink($file));
-
- $this->storage->touch($file);
- $statBefore = $this->storage->stat($file);
-
- $this->assertTrue(is_array($statBefore));
- $this->assertEquals($root['fileid'], $statBefore['parent']);
- $this->assertEquals($file, $statBefore['path']);
- $this->assertEquals($file, $statBefore['name']);
- $this->assertEquals(0, $statBefore['size']);
-
- $this->assertTrue($this->storage->unlink($file));
-
- $this->assertFalse($this->storage->stat($file));
-
- //TODO test folders
- }
-
- /**
- * checks several methods by creating directories:
- * - file_exists (f/t)
- * - mkdir (t/f)
- * - is_dir (t)
- * - is_file (f)
- * - filetype ('dir')
- * - filesize (0)
- * - isReadable (t)
- * - isUpdateable (t)
- * - opendir (dir array/empty array)
- * - rmdir (t/f)
- * @dataProvider directoryProvider
- */
- public function testDirectories($directory) {
- $this->assertFalse($this->storage->file_exists('/' . $directory), 'Expected /'.$directory.' to not exist');
-
- $this->assertTrue($this->storage->mkdir('/' . $directory), 'Expected creating /'.$directory.' to succeed');
-
- $this->assertTrue($this->storage->file_exists('/' . $directory), 'Expected /'.$directory.' to exist');
- $this->assertTrue($this->storage->is_dir('/' . $directory), 'Expected /'.$directory.' to be a directory');
- $this->assertFalse($this->storage->is_file('/' . $directory), 'Expected /'.$directory.' not to be a file');
- $this->assertEquals('dir', $this->storage->filetype('/' . $directory), 'Expected /'.$directory.' to have filetype \'dir\'');
- $this->assertEquals(0, $this->storage->filesize('/' . $directory), 'Expected /'.$directory.' to have size 0');
- $this->assertTrue($this->storage->isReadable('/' . $directory), 'Expected /'.$directory.' to be readable');
- $this->assertTrue($this->storage->isUpdatable('/' . $directory), 'Expected /'.$directory.' to be updateable');
-
- $dh = $this->storage->opendir('');
- $content = array();
- while ($file = readdir($dh)) {
- if ($file != '.' and $file != '..') {
- $content[] = $file;
- }
- }
- $this->assertEquals(array($directory), $content);
-
- $this->assertFalse($this->storage->mkdir('/' . $directory), 'Expected already existing folder /'.$directory.' to not be createable');
- $this->assertTrue($this->storage->rmdir('/' . $directory));
-
- $this->assertFalse($this->storage->file_exists('/' . $directory));
-
- $this->assertFalse($this->storage->rmdir('/' . $directory), 'Expected not existing folder /'.$directory.' to not be removable');
-
- $dh = $this->storage->opendir('/');
- $content = array();
- while ($file = readdir($dh)) {
- if ($file != '.' and $file != '..') {
- $content[] = $file;
- }
- }
- $this->assertEquals(array(), $content);
- }
-
- public function directoryProvider() {
- return array(
- array('folder'),
- array(' folder'),
- array('folder '),
- array('folder with space'),
- array('spéciäl földer'),
- array('☠ skull and crossbones'),
- array('skull and crossbones ☠ in between'),
- array('💩 pile of poo'),
- array('pile of 💩'),
- // check if someone tries to guess type on a date string
- array('2013-04-25'),
- );
- }
-
- public function testCopyAndMove() {
- $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
- $this->storage->file_put_contents('/source.txt', file_get_contents($textFile));
- $this->storage->copy('/source.txt', '/target.txt');
- $this->assertTrue($this->storage->file_exists('/target.txt'));
- $this->assertEquals($this->storage->file_get_contents('/source.txt'), $this->storage->file_get_contents('/target.txt'));
-
- $this->storage->rename('/source.txt', '/target2.txt');
- $this->assertTrue($this->storage->file_exists('/target2.txt'));
- $this->assertFalse($this->storage->file_exists('/source.txt'));
- $this->assertEquals(file_get_contents($textFile), $this->storage->file_get_contents('/target2.txt'));
-
- // move to overwrite
- $testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $this->storage->file_put_contents('/target3.txt', $testContents);
- $this->storage->rename('/target2.txt', '/target3.txt');
- $this->assertTrue($this->storage->file_exists('/target3.txt'));
- $this->assertFalse($this->storage->file_exists('/target2.txt'));
- $this->assertEquals(file_get_contents($textFile), $this->storage->file_get_contents('/target3.txt'));
- }
-
- //fopen
- //filetype test
- //getMimetype
- //getURN?!?!
- //test?
- //getConnection
- //writeback
}