]> source.dussan.org Git - nextcloud-server.git/commitdiff
remove unencrypted_size from the cache, size will contain the unencrypted size
authorBjoern Schiessle <schiessle@owncloud.com>
Mon, 30 Mar 2015 15:29:05 +0000 (17:29 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:28 +0000 (13:30 +0200)
apps/files_sharing/lib/cache.php
apps/files_sharing/lib/share/file.php
lib/private/files/cache/cache.php
lib/private/files/cache/homecache.php
lib/private/files/fileinfo.php
lib/private/files/storage/wrapper/encryption.php
lib/private/files/storage/wrapper/quota.php
lib/private/files/stream/encryption.php
lib/private/share/share.php
tests/lib/files/cache/cache.php
tests/lib/files/storage/wrapper/quota.php

index 69b8f629393be2552618d33ba946c26f4f25302b..e9b2addea388e4e2089e9df2db9c161fe6fffc4c 100644 (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'] = '';
index 22d6f29ff940d50ac2e8158cbbdd3567bb8ce781..1822c2468f1fb3a183b007197886349dffbb361c 100644 (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;
index 9a785d071f7b59ecc08cfb54fc9896c66240e0d9..c5e118946e5d6b37a81bdf424cbd3813cea75c66 100644 (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();
                        }
index aa075d41221c1e9334739ba179ddc727897e329a..1b85462d6155e2dc8dc0471a83a00a8343c976c9 100644 (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;
index 03aad56e10317e7560eeba933e020661dd0222bc..82c8f3de690179ad253728b6010b87ccab511113 100644 (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
         */
index a9e65a0014778b3b5db6420627dc2eda024dfd53..8892194f32b275e4f5d9252013f7c4774cefed1a 100644 (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);
                }
 
index 34bd2589947b561c96a8d76180db75ea0bec710f..3c0fda98dad08d49501f03fad35ea752eb8ba22a 100644 (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;
index df74eeff893f3a97c0b982c232fca65aba3d8627..e3927edff2c96df950e2eec25f72b1057ec3f74b 100644 (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;
index 90f3f28f2ee297a4763178ef7eb9c8fef9077318..98c612d5eb6f91e491000f86b03fbbafa43876cc 100644 (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`,'
index f0ad6cf3ab123eb38e4202fbbb3bd161688de0db..3d7f77cb54e6d0eb4e1bb5cb05d3b78e8812005e 100644 (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);
index 8ca8f308b71546bb872028c88e014dff747b527d..ec2c907ba9098649a2168da78ce616fc635f15dd 100644 (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(''));
        }