Cache: hash long storage ids to ensure they fit in the database
This commit is contained in:
parent
425d41aaf9
commit
0c1ec758e8
|
@ -48,6 +48,9 @@ class Cache {
|
||||||
} else {
|
} else {
|
||||||
$this->storageId = $storage;
|
$this->storageId = $storage;
|
||||||
}
|
}
|
||||||
|
if (strlen($this->storageId) > 64) {
|
||||||
|
$this->storageId = md5($this->storageId);
|
||||||
|
}
|
||||||
|
|
||||||
$query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?');
|
$query = \OC_DB::prepare('SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?');
|
||||||
$result = $query->execute(array($this->storageId));
|
$result = $query->execute(array($this->storageId));
|
||||||
|
|
|
@ -93,6 +93,9 @@ class Mount {
|
||||||
$this->storage = $this->createStorage();
|
$this->storage = $this->createStorage();
|
||||||
}
|
}
|
||||||
$this->storageId = $this->storage->getId();
|
$this->storageId = $this->storage->getId();
|
||||||
|
if (strlen($this->storageId) > 64) {
|
||||||
|
$this->storageId = md5($this->storageId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->storageId;
|
return $this->storageId;
|
||||||
}
|
}
|
||||||
|
@ -177,6 +180,9 @@ class Mount {
|
||||||
* @return \OC\Files\Storage\Storage[]
|
* @return \OC\Files\Storage\Storage[]
|
||||||
*/
|
*/
|
||||||
public static function findById($id) {
|
public static function findById($id) {
|
||||||
|
if (strlen($id) > 64) {
|
||||||
|
$id = md5($id);
|
||||||
|
}
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach (self::$mounts as $mount) {
|
foreach (self::$mounts as $mount) {
|
||||||
if ($mount->getStorageId() === $id) {
|
if ($mount->getStorageId() === $id) {
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
|
|
||||||
namespace Test\Files\Cache;
|
namespace Test\Files\Cache;
|
||||||
|
|
||||||
|
class LongId extends \OC\Files\Storage\Temporary {
|
||||||
|
public function getId() {
|
||||||
|
return 'long:' . str_repeat('foo', 50) . parent::getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Cache extends \PHPUnit_Framework_TestCase {
|
class Cache extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Temporary $storage;
|
* @var \OC\Files\Storage\Temporary $storage;
|
||||||
|
@ -204,6 +210,15 @@ class Cache extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
|
$this->assertEquals(array($storageId, 'foo'), \OC\Files\Cache\Cache::getById($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testLongId() {
|
||||||
|
$storage = new LongId(array());
|
||||||
|
$cache = $storage->getCache();
|
||||||
|
$storageId = $storage->getId();
|
||||||
|
$data = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
|
||||||
|
$id = $cache->put('foo', $data);
|
||||||
|
$this->assertEquals(array(md5($storageId), 'foo'), \OC\Files\Cache\Cache::getById($id));
|
||||||
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,12 @@ namespace Test\Files;
|
||||||
|
|
||||||
use \OC\Files\Storage\Temporary;
|
use \OC\Files\Storage\Temporary;
|
||||||
|
|
||||||
|
class LongId extends Temporary {
|
||||||
|
public function getId() {
|
||||||
|
return 'long:' . str_repeat('foo', 50) . parent::getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Mount extends \PHPUnit_Framework_TestCase {
|
class Mount extends \PHPUnit_Framework_TestCase {
|
||||||
public function setup() {
|
public function setup() {
|
||||||
\OC_Util::setupFS();
|
\OC_Util::setupFS();
|
||||||
|
@ -38,4 +44,15 @@ class Mount extends \PHPUnit_Framework_TestCase {
|
||||||
$mount2 = new \OC\Files\Mount($storage, '/foo/bar');
|
$mount2 = new \OC\Files\Mount($storage, '/foo/bar');
|
||||||
$this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id));
|
$this->assertEquals(array($mount, $mount2), \OC\Files\Mount::findById($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLong() {
|
||||||
|
$storage = new LongId(array());
|
||||||
|
$mount = new \OC\Files\Mount($storage, '/foo');
|
||||||
|
|
||||||
|
$id = $mount->getStorageId();
|
||||||
|
$storageId = $storage->getId();
|
||||||
|
$this->assertEquals(array($mount), \OC\Files\Mount::findById($id));
|
||||||
|
$this->assertEquals(array($mount), \OC\Files\Mount::findById($storageId));
|
||||||
|
$this->assertEquals(array($mount), \OC\Files\Mount::findById(md5($storageId)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue