remove unencrypted_size from the cache, size will contain the unencrypted size

This commit is contained in:
Bjoern Schiessle 2015-03-30 17:29:05 +02:00 committed by Thomas Müller
parent d185761d31
commit 0eee3a2618
11 changed files with 25 additions and 82 deletions

View File

@ -122,7 +122,7 @@ class Shared_Cache extends Cache {
}
$query = \OC_DB::prepare(
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`,'
. ' `size`, `mtime`, `encrypted`, `unencrypted_size`, `storage_mtime`, `etag`, `permissions`'
. ' `size`, `mtime`, `encrypted`, `storage_mtime`, `etag`, `permissions`'
. ' FROM `*PREFIX*filecache` WHERE `fileid` = ?');
$result = $query->execute(array($sourceId));
$data = $result->fetchRow();
@ -135,12 +135,7 @@ class Shared_Cache extends Cache {
if ($data['storage_mtime'] === 0) {
$data['storage_mtime'] = $data['mtime'];
}
if ($data['encrypted'] or ($data['unencrypted_size'] > 0 and $data['mimetype'] === 'httpd/unix-directory')) {
$data['encrypted_size'] = (int)$data['size'];
$data['size'] = (int)$data['unencrypted_size'];
} else {
$data['size'] = (int)$data['size'];
}
$data['size'] = (int)$data['size'];
$data['permissions'] = (int)$data['permissions'];
if (!is_int($file) || $file === 0) {
$data['path'] = '';

View File

@ -128,12 +128,7 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
$storage = \OC\Files\Filesystem::getStorage('/');
$cache = $storage->getCache();
if ($item['encrypted'] or ($item['unencrypted_size'] > 0 and $cache->getMimetype($item['mimetype']) === 'httpd/unix-directory')) {
$file['size'] = $item['unencrypted_size'];
$file['encrypted_size'] = $item['size'];
} else {
$file['size'] = $item['size'];
}
$file['size'] = $item['size'];
$files[] = $file;
}
return $files;

View File

@ -152,7 +152,7 @@ class Cache {
$params = array($file);
}
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
`storage_mtime`, `encrypted`, `unencrypted_size`, `etag`, `permissions`
`storage_mtime`, `encrypted`, `etag`, `permissions`
FROM `*PREFIX*filecache` ' . $where;
$result = \OC_DB::executeAudited($sql, $params);
$data = $result->fetchRow();
@ -175,7 +175,6 @@ class Cache {
$data['mtime'] = (int)$data['mtime'];
$data['storage_mtime'] = (int)$data['storage_mtime'];
$data['encrypted'] = (bool)$data['encrypted'];
$data['unencrypted_size'] = 0 + $data['unencrypted_size'];
$data['storage'] = $this->storageId;
$data['mimetype'] = $this->getMimetype($data['mimetype']);
$data['mimepart'] = $this->getMimetype($data['mimepart']);
@ -208,7 +207,7 @@ class Cache {
public function getFolderContentsById($fileId) {
if ($fileId > -1) {
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
`storage_mtime`, `encrypted`, `unencrypted_size`, `etag`, `permissions`
`storage_mtime`, `encrypted`, `etag`, `permissions`
FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
$result = \OC_DB::executeAudited($sql, array($fileId));
$files = $result->fetchAll();
@ -218,10 +217,6 @@ class Cache {
if ($file['storage_mtime'] == 0) {
$file['storage_mtime'] = $file['mtime'];
}
if ($file['encrypted'] or ($file['unencrypted_size'] > 0 and $file['mimetype'] === 'httpd/unix-directory')) {
$file['encrypted_size'] = $file['size'];
$file['size'] = $file['unencrypted_size'];
}
$file['permissions'] = (int)$file['permissions'];
$file['mtime'] = (int)$file['mtime'];
$file['storage_mtime'] = (int)$file['storage_mtime'];
@ -325,7 +320,7 @@ class Cache {
*/
function buildParts(array $data) {
$fields = array(
'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted', 'unencrypted_size',
'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
'etag', 'permissions');
$params = array();
$queryParts = array();
@ -521,7 +516,7 @@ class Cache {
$sql = '
SELECT `fileid`, `storage`, `path`, `parent`, `name`,
`mimetype`, `mimepart`, `size`, `mtime`, `encrypted`,
`unencrypted_size`, `etag`, `permissions`
`etag`, `permissions`
FROM `*PREFIX*filecache`
WHERE `storage` = ? AND `name` ILIKE ?';
$result = \OC_DB::executeAudited($sql,
@ -549,7 +544,7 @@ class Cache {
} else {
$where = '`mimepart` = ?';
}
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`, `permissions`
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions`
FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
$mimetype = $this->getMimetypeId($mimetype);
$result = \OC_DB::executeAudited($sql, array($mimetype, $this->getNumericStorageId()));
@ -574,7 +569,7 @@ class Cache {
public function searchByTag($tag, $userId) {
$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' .
'`mimetype`, `mimepart`, `size`, `mtime`, ' .
'`encrypted`, `unencrypted_size`, `etag`, `permissions` ' .
'`encrypted`, `etag`, `permissions` ' .
'FROM `*PREFIX*filecache` `file`, ' .
'`*PREFIX*vcategory_to_object` `tagmap`, ' .
'`*PREFIX*vcategory` `tag` ' .
@ -638,17 +633,15 @@ class Cache {
}
if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
$sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2, ' .
'SUM(`unencrypted_size`) AS f3 ' .
$sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' .
'FROM `*PREFIX*filecache` ' .
'WHERE `parent` = ? AND `storage` = ?';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
$result->closeCursor();
list($sum, $min, $unencryptedSum) = array_values($row);
list($sum, $min) = array_values($row);
$sum = 0 + $sum;
$min = 0 + $min;
$unencryptedSum = 0 + $unencryptedSum;
if ($min === -1) {
$totalSize = $min;
} else {
@ -658,15 +651,9 @@ class Cache {
if ($entry['size'] !== $totalSize) {
$update['size'] = $totalSize;
}
if (!isset($entry['unencrypted_size']) or $entry['unencrypted_size'] !== $unencryptedSum) {
$update['unencrypted_size'] = $unencryptedSum;
}
if (count($update) > 0) {
$this->update($id, $update);
}
if ($totalSize !== -1 and $unencryptedSum > 0) {
$totalSize = $unencryptedSum;
}
} else {
$result->closeCursor();
}

View File

@ -48,26 +48,18 @@ class HomeCache extends Cache {
}
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
$id = $entry['fileid'];
$sql = 'SELECT SUM(`size`) AS f1, ' .
'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' .
$sql = 'SELECT SUM(`size`) AS f1 ' .
'FROM `*PREFIX*filecache` ' .
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
$result->closeCursor();
list($sum, $unencryptedSum) = array_values($row);
list($sum) = array_values($row);
$totalSize = 0 + $sum;
$unencryptedSize = 0 + $unencryptedSum;
$entry['size'] += 0;
if (!isset($entry['unencrypted_size'])) {
$entry['unencrypted_size'] = 0;
}
$entry['unencrypted_size'] += 0;
if ($entry['size'] !== $totalSize) {
$this->update($id, array('size' => $totalSize));
}
if ($entry['unencrypted_size'] !== $unencryptedSize) {
$this->update($id, array('unencrypted_size' => $unencryptedSize));
}
}
}
return $totalSize;

View File

@ -167,13 +167,6 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
return $this->data['encrypted'];
}
/**
* @return int
*/
public function getUnencryptedSize() {
return isset($this->data['unencrypted_size']) ? $this->data['unencrypted_size'] : 0;
}
/**
* @return int
*/

View File

@ -77,27 +77,15 @@ class Encryption extends Wrapper {
* @return int
*/
public function filesize($path) {
$size = 0;
$fullPath = $this->getFullPath($path);
$encryptedSize = $this->storage->filesize($path);
$size = $this->storage->filesize($path);
$info = $this->getCache()->get($path);
if($encryptedSize > 0 && $info['encrypted']) {
$size = $info['unencrypted_size'];
if ($size <= 0) {
$encryptionModule = $this->getEncryptionModule($path);
if ($encryptionModule) {
$size = $encryptionModule->calculateUnencryptedSize($fullPath);
$this->getCache()->update($info['fileid'], array('unencrypted_size' => $size));
}
}
} else if (isset($this->unencryptedSize[$fullPath]) && isset($info['fileid'])) {
if (isset($this->unencryptedSize[$fullPath]) && isset($info['fileid'])) {
$size = $this->unencryptedSize[$fullPath];
$info['encrypted'] = true;
$info['unencrypted_size'] = $size;
$info['size'] = $encryptedSize;
$info['size'] = $size;
$this->getCache()->put($path, $info);
}

View File

@ -60,11 +60,6 @@ class Quota extends Wrapper {
$cache = $this->getCache();
$data = $cache->get($path);
if (is_array($data) and isset($data['size'])) {
if (isset($data['unencrypted_size'])
&& $data['unencrypted_size'] > 0
) {
return $data['unencrypted_size'];
}
return $data['size'];
} else {
return \OCP\Files\FileInfo::SPACE_NOT_COMPUTED;

View File

@ -271,7 +271,8 @@ class Encryption extends Wrapper {
public function stream_write($data) {
if ($this->position === 0) {
$this->size+=$this->writeHeader();
$this->writeHeader();
$this->size+=$this->util->getHeaderSize();
}
$length = 0;

View File

@ -2214,7 +2214,7 @@ class Share extends \OC\Share\Constants {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`, `uid_owner`, '
. '`share_type`, `share_with`, `file_source`, `path`, `file_target`, `stime`, '
. '`*PREFIX*share`.`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, '
. '`name`, `mtime`, `mimetype`, `mimepart`, `size`, `unencrypted_size`, `encrypted`, `etag`, `mail_send`';
. '`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`';
} else {
$select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`,'
. '`*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`,'

View File

@ -183,8 +183,8 @@ class Cache extends \Test\TestCase {
$file3 = 'folder/foo';
$data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
$fileData = array();
$fileData['bar'] = array('size' => 1000, 'unencrypted_size' => 900, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
$fileData['foo'] = array('size' => 20, 'unencrypted_size' => 16, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
$fileData['bar'] = array('size' => 1000, 'encrypted' => 1, 'mtime' => 20, 'mimetype' => 'foo/file');
$fileData['foo'] = array('size' => 20, 'encrypted' => 1, 'mtime' => 25, 'mimetype' => 'foo/file');
$this->cache->put($file1, $data1);
$this->cache->put($file2, $fileData['bar']);
@ -194,8 +194,6 @@ class Cache extends \Test\TestCase {
$this->assertEquals(count($content), 2);
foreach ($content as $cachedData) {
$data = $fileData[$cachedData['name']];
// indirect retrieval swaps unencrypted_size and size
$this->assertEquals($data['unencrypted_size'], $cachedData['size']);
}
$file4 = 'folder/unkownSize';
@ -211,7 +209,6 @@ class Cache extends \Test\TestCase {
// direct cache entry retrieval returns the original values
$entry = $this->cache->get($file1);
$this->assertEquals(1025, $entry['size']);
$this->assertEquals(916, $entry['unencrypted_size']);
$this->cache->remove($file2);
$this->cache->remove($file3);

View File

@ -59,7 +59,7 @@ class Quota extends \Test\Files\Storage\Storage {
public function testFreeSpaceWithUsedSpace() {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
'', array('size' => 3, 'unencrypted_size' => 0)
'', array('size' => 3)
);
$this->assertEquals(6, $instance->free_space(''));
}
@ -77,7 +77,7 @@ class Quota extends \Test\Files\Storage\Storage {
$instance = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => 9));
$instance->getCache()->put(
'', array('size' => 3, 'unencrypted_size' => 0)
'', array('size' => 3)
);
$this->assertEquals(6, $instance->free_space(''));
}
@ -85,7 +85,7 @@ class Quota extends \Test\Files\Storage\Storage {
public function testFreeSpaceWithUsedSpaceAndEncryption() {
$instance = $this->getLimitedStorage(9);
$instance->getCache()->put(
'', array('size' => 7, 'unencrypted_size' => 3)
'', array('size' => 7)
);
$this->assertEquals(6, $instance->free_space(''));
}