Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2013-11-12 18:46:01 +0400
committerVincent Petry <pvince81@owncloud.com>2013-11-12 21:01:02 +0400
commit34c92f665639baf6ea86a265855a2b2862755537 (patch)
treec8cc2b73f2cee74a449593673bf4213dbb4e81e7
parent1a65e3a72593a2eb343386e5008faea78f0b9c8f (diff)
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.
-rw-r--r--lib/private/files/filesystem.php14
-rw-r--r--lib/private/files/storage/home.php14
-rw-r--r--tests/lib/files/filesystem.php64
-rw-r--r--tests/lib/files/storage/home.php29
4 files changed, 115 insertions, 6 deletions
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
@@ -13,6 +13,11 @@ namespace OC\Files\Storage;
*/
class Home extends Local {
/**
+ * @var string
+ */
+ protected $id;
+
+ /**
* @var \OC\User\User $user
*/
protected $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());
+ }
}