From 3cb666ad7732cd2bff5cc172e40d1b22407aa640 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 21 Oct 2013 13:21:39 +0200 Subject: chunked files are assembled into a part file on the target storage followed by an atomic rename operation. --- lib/private/connector/sabre/file.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 3402946a136..85b67e65871 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -223,9 +223,22 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D } if ($chunk_handler->isComplete()) { - $newPath = $path . '/' . $info['name']; - $chunk_handler->file_assemble($newPath); - return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); + + // we first assembly the target file as a part file + $partFile = $path . '/' . $info['name'] . '-' . $info['transferid'] . '.part'; + $chunk_handler->file_assemble($partFile); + + // here is the final atomic rename + $fs = $this->getFS(); + $targetPath = $path . '/' . $info['name']; + $renameOkay = $fs->rename($partFile, $targetPath); + $fileExists = $fs->file_exists($targetPath); + if ($renameOkay === false || $fileExists === false) { + \OC_Log::write('webdav', '\OC\Files\Filesystem::rename() failed', \OC_Log::ERROR); + $fs->unlink($targetPath); + throw new Sabre_DAV_Exception(); + } + return OC_Connector_Sabre_Node::getETagPropertyForPath($targetPath); } return null; -- cgit v1.2.3 From 2628601e79b8bebfdd6b1a03ef915ca9b1bd629a Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 21 Oct 2013 15:00:28 +0200 Subject: adding oc-mtime handling to chunked upload --- lib/private/connector/sabre/file.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 85b67e65871..8621b7f3689 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -238,6 +238,15 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D $fs->unlink($targetPath); throw new Sabre_DAV_Exception(); } + + // allow sync clients to send the mtime along in a header + $mtime = OC_Request::hasModificationTime(); + if ($mtime !== false) { + if($fs->touch($this->path, $mtime)) { + header('X-OC-MTime: accepted'); + } + } + return OC_Connector_Sabre_Node::getETagPropertyForPath($targetPath); } -- cgit v1.2.3 From 68f3f2e691a254349efb1f15953659b42ce8ad3e Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 11 Nov 2013 17:47:46 +0100 Subject: make it possible to detect transferID part --- lib/private/connector/sabre/file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 8621b7f3689..cec3c0ed7e2 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -225,7 +225,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D if ($chunk_handler->isComplete()) { // we first assembly the target file as a part file - $partFile = $path . '/' . $info['name'] . '-' . $info['transferid'] . '.part'; + $partFile = $path . '/' . $info['name'] . '.ocTransferId' . $info['transferid'] . '.part'; $chunk_handler->file_assemble($partFile); // here is the final atomic rename -- cgit v1.2.3 From 32a703ab3643842d3262fcc8c6ac014c3e54d8ea Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 8 Nov 2013 12:57:28 +0100 Subject: Do not use -1 as the size for the root folder of the home storage --- lib/private/files/cache/homecache.php | 48 ++++++++++++++++++ lib/private/files/storage/common.php | 10 ++-- lib/private/files/storage/home.php | 7 +++ tests/lib/files/cache/cache.php | 55 ++++++++++++++------ tests/lib/files/cache/homecache.php | 95 +++++++++++++++++++++++++++++++++++ 5 files changed, 196 insertions(+), 19 deletions(-) create mode 100644 lib/private/files/cache/homecache.php create mode 100644 tests/lib/files/cache/homecache.php (limited to 'lib') diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php new file mode 100644 index 00000000000..4439896e6e7 --- /dev/null +++ b/lib/private/files/cache/homecache.php @@ -0,0 +1,48 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Cache; + +class HomeCache extends Cache { + /** + * get the size of a folder and set it in the cache + * + * @param string $path + * @return int + */ + public function calculateFolderSize($path) { + $totalSize = 0; + $entry = $this->get($path); + if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { + $isRoot = ($path === '/' or $path === ''); + $id = $entry['fileid']; + $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` ' . + 'WHERE `parent` = ? AND `storage` = ?'; + if ($isRoot) { + // filter out non-scanned dirs at the root + $sql .= ' AND `size` >= 0'; + } + $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); + if ($row = $result->fetchRow()) { + list($sum, $min) = array_values($row); + $sum = (int)$sum; + $min = (int)$min; + if ($min === -1) { + $totalSize = $min; + } else { + $totalSize = $sum; + } + if ($entry['size'] !== $totalSize) { + $this->update($id, array('size' => $totalSize)); + } + + } + } + return $totalSize; + } +} diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index a5b79f0e967..3943d667c35 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -21,11 +21,11 @@ namespace OC\Files\Storage; */ abstract class Common implements \OC\Files\Storage\Storage { - private $cache; - private $scanner; - private $permissioncache; - private $watcher; - private $storageCache; + protected $cache; + protected $scanner; + protected $permissioncache; + protected $watcher; + protected $storageCache; public function __construct($parameters) { } diff --git a/lib/private/files/storage/home.php b/lib/private/files/storage/home.php index bf1d6017cbf..22753519ad3 100644 --- a/lib/private/files/storage/home.php +++ b/lib/private/files/storage/home.php @@ -27,4 +27,11 @@ class Home extends Local { public function getId() { return 'home::' . $this->user->getUID(); } + + public function getCache($path = '') { + if (!isset($this->cache)) { + $this->cache = new \OC\Files\Cache\HomeCache($this); + } + return $this->cache; + } } diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index 247373a5cb9..052d70dd0b4 100644 --- a/tests/lib/files/cache/cache.php +++ b/tests/lib/files/cache/cache.php @@ -18,11 +18,11 @@ class LongId extends \OC\Files\Storage\Temporary { class Cache extends \PHPUnit_Framework_TestCase { /** - * @var \OC\Files\Storage\Temporary $storage; + * @var \OC\Files\Storage\Temporary $storage ; */ private $storage; /** - * @var \OC\Files\Storage\Temporary $storage2; + * @var \OC\Files\Storage\Temporary $storage2 ; */ private $storage2; @@ -137,6 +137,33 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertFalse($this->cache->inCache('folder/bar')); } + public function testRootFolderSizeForNonHomeStorage() { + $dir1 = 'knownsize'; + $dir2 = 'unknownsize'; + $fileData = array(); + $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); + $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); + $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory'); + + $this->cache->put('', $fileData['']); + $this->cache->put($dir1, $fileData[$dir1]); + $this->cache->put($dir2, $fileData[$dir2]); + + $this->assertTrue($this->cache->inCache($dir1)); + $this->assertTrue($this->cache->inCache($dir2)); + + // check that root size ignored the unknown sizes + $this->assertEquals(-1, $this->cache->calculateFolderSize('')); + + // clean up + $this->cache->remove(''); + $this->cache->remove($dir1); + $this->cache->remove($dir2); + + $this->assertFalse($this->cache->inCache($dir1)); + $this->assertFalse($this->cache->inCache($dir2)); + } + function testStatus() { $this->assertEquals(\OC\Files\Cache\Cache::NOT_FOUND, $this->cache->getStatus('foo')); $this->cache->put('foo', array('size' => -1)); @@ -247,14 +274,14 @@ class Cache extends \PHPUnit_Framework_TestCase { $data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file'); $this->cache->put('foo', $data); $cachedData = $this->cache->get('foo'); - $this->assertEquals($data['mtime'], $cachedData['storage_mtime']);//if no storage_mtime is saved, mtime should be used + $this->assertEquals($data['mtime'], $cachedData['storage_mtime']); //if no storage_mtime is saved, mtime should be used - $this->cache->put('foo', array('storage_mtime' => 30));//when setting storage_mtime, mtime is also set + $this->cache->put('foo', array('storage_mtime' => 30)); //when setting storage_mtime, mtime is also set $cachedData = $this->cache->get('foo'); $this->assertEquals(30, $cachedData['storage_mtime']); $this->assertEquals(30, $cachedData['mtime']); - $this->cache->put('foo', array('mtime' => 25));//setting mtime does not change storage_mtime + $this->cache->put('foo', array('mtime' => 25)); //setting mtime does not change storage_mtime $cachedData = $this->cache->get('foo'); $this->assertEquals(30, $cachedData['storage_mtime']); $this->assertEquals(25, $cachedData['mtime']); @@ -295,18 +322,18 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertGreaterThan(0, $cacheMock->put('folder', $data)); // put un-normalized folder - $this->assertFalse($cacheMock->get('folder/' .$folderWith0308)); - $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith0308, $data)); + $this->assertFalse($cacheMock->get('folder/' . $folderWith0308)); + $this->assertGreaterThan(0, $cacheMock->put('folder/' . $folderWith0308, $data)); // get un-normalized folder by name - $unNormalizedFolderName = $cacheMock->get('folder/' .$folderWith0308); + $unNormalizedFolderName = $cacheMock->get('folder/' . $folderWith0308); // check if database layer normalized the folder name (this should not happen) $this->assertEquals($folderWith0308, $unNormalizedFolderName['name']); // put normalized folder $this->assertFalse($cacheMock->get('folder/' . $folderWith00F6)); - $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith00F6, $data)); + $this->assertGreaterThan(0, $cacheMock->put('folder/' . $folderWith00F6, $data)); // this is our bug, we have two different hashes with the same name (Schön) $this->assertEquals(2, count($cacheMock->getFolderContents('folder'))); @@ -317,7 +344,7 @@ class Cache extends \PHPUnit_Framework_TestCase { */ public function testWithNormalizer() { - if(!class_exists('Patchwork\PHP\Shim\Normalizer')) { + if (!class_exists('Patchwork\PHP\Shim\Normalizer')) { $this->markTestSkipped('The 3rdparty Normalizer extension is not available.'); return; } @@ -335,18 +362,18 @@ class Cache extends \PHPUnit_Framework_TestCase { $this->assertGreaterThan(0, $this->cache->put('folder', $data)); // put un-normalized folder - $this->assertFalse($this->cache->get('folder/' .$folderWith0308)); - $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith0308, $data)); + $this->assertFalse($this->cache->get('folder/' . $folderWith0308)); + $this->assertGreaterThan(0, $this->cache->put('folder/' . $folderWith0308, $data)); // get un-normalized folder by name - $unNormalizedFolderName = $this->cache->get('folder/' .$folderWith0308); + $unNormalizedFolderName = $this->cache->get('folder/' . $folderWith0308); // check if folder name was normalized $this->assertEquals($folderWith00F6, $unNormalizedFolderName['name']); // put normalized folder $this->assertTrue(is_array($this->cache->get('folder/' . $folderWith00F6))); - $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith00F6, $data)); + $this->assertGreaterThan(0, $this->cache->put('folder/' . $folderWith00F6, $data)); // at this point we should have only one folder named "Schön" $this->assertEquals(1, count($this->cache->getFolderContents('folder'))); diff --git a/tests/lib/files/cache/homecache.php b/tests/lib/files/cache/homecache.php new file mode 100644 index 00000000000..ebf2b7270da --- /dev/null +++ b/tests/lib/files/cache/homecache.php @@ -0,0 +1,95 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Files\Cache; + +class DummyUser extends \OC\User\User { + /** + * @var string $home + */ + private $home; + + /** + * @var string $uid + */ + private $uid; + + public function __construct($uid, $home) { + $this->home = $home; + $this->uid = $uid; + } + + /** + * @return string + */ + public function getHome() { + return $this->home; + } + + /** + * @return string + */ + public function getUID() { + return $this->uid; + } +} + +class HomeCache extends \PHPUnit_Framework_TestCase { + /** + * @var \OC\Files\Storage\Home $storage + */ + private $storage; + + /** + * @var \OC\Files\Cache\HomeCache $cache + */ + private $cache; + + /** + * @var \OC\User\User $user + */ + private $user; + + public function setUp() { + $this->user = new DummyUser('foo', \OC_Helper::tmpFolder()); + $this->storage = new \OC\Files\Storage\Home(array('user' => $this->user)); + $this->cache = $this->storage->getCache(); + } + + /** + * Tests that the root folder size calculation ignores the subdirs that have an unknown + * size. This makes sure that quota calculation still works as it's based on the root + * folder size. + */ + public function testRootFolderSizeIgnoresUnknownUpdate() { + $dir1 = 'knownsize'; + $dir2 = 'unknownsize'; + $fileData = array(); + $fileData[''] = array('size' => -1, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); + $fileData[$dir1] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'httpd/unix-directory'); + $fileData[$dir2] = array('size' => -1, 'mtime' => 25, 'mimetype' => 'httpd/unix-directory'); + + $this->cache->put('', $fileData['']); + $this->cache->put($dir1, $fileData[$dir1]); + $this->cache->put($dir2, $fileData[$dir2]); + + $this->assertTrue($this->cache->inCache($dir1)); + $this->assertTrue($this->cache->inCache($dir2)); + + // check that root size ignored the unknown sizes + $this->assertEquals(1000, $this->cache->calculateFolderSize('')); + + // clean up + $this->cache->remove(''); + $this->cache->remove($dir1); + $this->cache->remove($dir2); + + $this->assertFalse($this->cache->inCache($dir1)); + $this->assertFalse($this->cache->inCache($dir2)); + } +} -- cgit v1.2.3 From 1a65e3a72593a2eb343386e5008faea78f0b9c8f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 12 Nov 2013 14:17:55 +0100 Subject: Now calling parent method when path is not root --- lib/private/files/cache/homecache.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php index 4439896e6e7..4b14bd12190 100644 --- a/lib/private/files/cache/homecache.php +++ b/lib/private/files/cache/homecache.php @@ -16,31 +16,23 @@ class HomeCache extends Cache { * @return int */ public function calculateFolderSize($path) { + if ($path !== '/' and $path !== '') { + return parent::calculateFolderSize($path); + } + $totalSize = 0; $entry = $this->get($path); if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { - $isRoot = ($path === '/' or $path === ''); $id = $entry['fileid']; - $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` ' . - 'WHERE `parent` = ? AND `storage` = ?'; - if ($isRoot) { - // filter out non-scanned dirs at the root - $sql .= ' AND `size` >= 0'; - } + $sql = 'SELECT SUM(`size`) FROM `*PREFIX*filecache` ' . + 'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0'; $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); if ($row = $result->fetchRow()) { - list($sum, $min) = array_values($row); - $sum = (int)$sum; - $min = (int)$min; - if ($min === -1) { - $totalSize = $min; - } else { - $totalSize = $sum; - } + list($sum) = array_values($row); + $totalSize = (int)$sum; if ($entry['size'] !== $totalSize) { $this->update($id, array('size' => $totalSize)); } - } } return $totalSize; -- cgit v1.2.3 From 34c92f665639baf6ea86a265855a2b2862755537 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Tue, 12 Nov 2013 15:46:01 +0100 Subject: Now using HomeStorage for legacy home storage ids Legacy home storage ids with the format "local://path/to/datadir/user1" are now also wrapped by the HomeStorage. --- lib/private/files/filesystem.php | 14 +++++++-- lib/private/files/storage/home.php | 14 ++++++++- tests/lib/files/filesystem.php | 64 ++++++++++++++++++++++++++++++++++++++ tests/lib/files/storage/home.php | 29 +++++++++++++++-- 4 files changed, 115 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index e40502bbe64..899666f3e1a 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -307,10 +307,18 @@ class Filesystem { $root = \OC_User::getHome($user); $userObject = \OC_User::getManager()->get($user); - if (\OC\Files\Cache\Storage::exists('local::' . $root . '/') or is_null($userObject)) { + + if (!is_null($userObject)) { + // check for legacy home id (<= 5.0.12) + if (\OC\Files\Cache\Storage::exists('local::' . $root . '/')) { + self::mount('\OC\Files\Storage\Home', array('user' => $userObject, 'legacy' => true), $user); + } + else { + self::mount('\OC\Files\Storage\Home', array('user' => $userObject), $user); + } + } + else { self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user); - } else { - self::mount('\OC\Files\Storage\Home', array('user' => $userObject), $user); } $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); diff --git a/lib/private/files/storage/home.php b/lib/private/files/storage/home.php index 22753519ad3..b4ceb8f4f9b 100644 --- a/lib/private/files/storage/home.php +++ b/lib/private/files/storage/home.php @@ -12,6 +12,11 @@ namespace OC\Files\Storage; * Specialized version of Local storage for home directory usage */ class Home extends Local { + /** + * @var string + */ + protected $id; + /** * @var \OC\User\User $user */ @@ -20,12 +25,19 @@ class Home extends Local { public function __construct($arguments) { $this->user = $arguments['user']; $datadir = $this->user->getHome(); + if (isset($arguments['legacy']) && $arguments['legacy']) { + // legacy home id (<= 5.0.12) + $this->id = 'local::' . $datadir . '/'; + } + else { + $this->id = 'home::' . $this->user->getUID(); + } parent::__construct(array('datadir' => $datadir)); } public function getId() { - return 'home::' . $this->user->getUID(); + return $this->id; } public function getCache($path = '') { diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index bef70cc725b..990e95ca595 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -41,9 +41,12 @@ class Filesystem extends \PHPUnit_Framework_TestCase { foreach ($this->tmpDirs as $dir) { \OC_Helper::rmdirr($dir); } + \OC\Files\Filesystem::clearMounts(); + \OC_User::setUserId(''); } public function setUp() { + \OC_User::setUserId(''); \OC\Files\Filesystem::clearMounts(); } @@ -103,6 +106,67 @@ class Filesystem extends \PHPUnit_Framework_TestCase { // \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh); } + /** + * Tests that a local storage mount is used when passed user + * does not exist. + */ + public function testLocalMountWhenUserDoesNotExist() { + $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); + $userId = uniqid('user_'); + + \OC\Files\Filesystem::initMountPoints($userId); + + $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); + + $this->assertInstanceOf('\OC\Files\Storage\Local', $homeMount); + $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); + } + + /** + * Tests that the home storage is used for the user's mount point + */ + public function testHomeMount() { + $userId = uniqid('user_'); + + \OC_User::createUser($userId, $userId); + + \OC\Files\Filesystem::initMountPoints($userId); + + $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); + + $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount); + $this->assertEquals('home::' . $userId, $homeMount->getId()); + + \OC_User::deleteUser($userId); + } + + /** + * Tests that the home storage is used in legacy mode + * for the user's mount point + */ + public function testLegacyHomeMount() { + $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); + $userId = uniqid('user_'); + + // insert storage into DB by constructing it + // to make initMountsPoint find its existence + $localStorage = new \OC\Files\Storage\Local(array('datadir' => $datadir . '/' . $userId . '/')); + // this will trigger the insert + $cache = $localStorage->getCache(); + + \OC_User::createUser($userId, $userId); + \OC\Files\Filesystem::initMountPoints($userId); + + $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); + + $this->assertInstanceOf('\OC\Files\Storage\Home', $homeMount); + $this->assertEquals('local::' . $datadir. '/' . $userId . '/', $homeMount->getId()); + + \OC_User::deleteUser($userId); + // delete storage entry + $cache->clear(); + } + public function dummyHook($arguments) { $path = $arguments['path']; $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized diff --git a/tests/lib/files/storage/home.php b/tests/lib/files/storage/home.php index b01e07f7457..885291e4404 100644 --- a/tests/lib/files/storage/home.php +++ b/tests/lib/files/storage/home.php @@ -56,8 +56,8 @@ class Home extends Storage { public function setUp() { $this->tmpDir = \OC_Helper::tmpFolder(); - $userId = uniqid('user_'); - $this->user = new DummyUser($userId, $this->tmpDir); + $this->userId = uniqid('user_'); + $this->user = new DummyUser($this->userId, $this->tmpDir); $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user)); } @@ -65,7 +65,32 @@ class Home extends Storage { \OC_Helper::rmdirr($this->tmpDir); } + /** + * Tests that the root path matches the data dir + */ public function testRoot() { $this->assertEquals($this->tmpDir, $this->instance->getLocalFolder('')); } + + /** + * Tests that the home id is in the format home::user1 + */ + public function testId() { + $this->assertEquals('home::' . $this->userId, $this->instance->getId()); + } + + /** + * Tests that the legacy home id is in the format local::/path/to/datadir/user1/ + */ + public function testLegacyId() { + $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user, 'legacy' => true)); + $this->assertEquals('local::' . $this->tmpDir . '/', $this->instance->getId()); + } + + /** + * Tests that getCache() returns an instance of HomeCache + */ + public function testGetCacheReturnsHomeCache() { + $this->assertInstanceOf('\OC\Files\Cache\HomeCache', $this->instance->getCache()); + } } -- cgit v1.2.3