From fdb0d2067ff66017a3cae76f1da7b18e94dc5364 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 19 Feb 2014 10:20:52 +0100 Subject: Remove duplicated definition and move OC.msg to js/js.js Fix issue #7166 --- apps/files_encryption/js/settings-admin.js | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/js/settings-admin.js b/apps/files_encryption/js/settings-admin.js index c2140a6f1eb..785d02002fa 100644 --- a/apps/files_encryption/js/settings-admin.js +++ b/apps/files_encryption/js/settings-admin.js @@ -7,28 +7,6 @@ * See the COPYING-README file. */ -OC.msg={ - startSaving:function(selector){ - $(selector) - .html( t('settings', 'Saving...') ) - .removeClass('success') - .removeClass('error') - .stop(true, true) - .show(); - }, - finishedSaving:function(selector, data){ - if( data.status === "success" ){ - $(selector).html( data.data.message ) - .addClass('success') - .stop(true, true) - .delay(3000) - .fadeOut(900); - }else{ - $(selector).html( data.data.message ).addClass('error'); - } - } -}; - $(document).ready(function(){ // Trigger ajax on recoveryAdmin status change var enabledStatus = $('#adminEnableRecovery').val(); -- cgit v1.2.3 From ebd73aee8ff96f7252fab65ab4dc7230d2eb551c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 24 Feb 2014 13:56:53 +0100 Subject: don't overwrite keys if rename was done by a stream copy --- apps/files_encryption/hooks/hooks.php | 17 +++++++++++++---- lib/private/files/view.php | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 3af43f10264..0b6c5adf3fb 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -501,11 +501,20 @@ class Hooks { * @param array $params with the old path and the new path */ public static function preRename($params) { - $util = new Util(new \OC_FilesystemView('/'), \OCP\User::getUser()); + $user = \OCP\User::getUser(); + $view = new \OC_FilesystemView('/'); + $util = new Util($view, $user); list($ownerOld, $pathOld) = $util->getUidAndFilename($params['oldpath']); - self::$renamedFiles[$params['oldpath']] = array( - 'uid' => $ownerOld, - 'path' => $pathOld); + + // we only need to rename the keys if the rename happens on the same mountpoint + // otherwise we perform a stream copy, so we get a new set of keys + $mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']); + $mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']); + if ($mp1 === $mp2) { + self::$renamedFiles[$params['oldpath']] = array( + 'uid' => $ownerOld, + 'path' => $pathOld); + } } /** diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 530aa8f7514..e2c565c5cbb 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -534,6 +534,8 @@ class View { $source = $this->fopen($path1 . $postFix1, 'r'); $target = $this->fopen($path2 . $postFix2, 'w'); list($count, $result) = \OC_Helper::streamCopy($source, $target); + fclose($source); + fclose($target); } } if ($this->shouldEmitHooks() && $result !== false) { -- cgit v1.2.3 From d3a24e945b72f07b51b5d9aa3e11c70a70bf9c8c Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Mon, 24 Feb 2014 16:33:57 +0100 Subject: add test case if a file gets moved out from the shared folder --- apps/files_encryption/tests/hooks.php | 55 +++++++++++++++++++++++++++ apps/files_encryption/tests/share.php | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/tests/hooks.php b/apps/files_encryption/tests/hooks.php index 7d926caea1b..d0e4b5f732e 100644 --- a/apps/files_encryption/tests/hooks.php +++ b/apps/files_encryption/tests/hooks.php @@ -47,6 +47,7 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase { public $rootView; // view on /data/user public $data; public $filename; + public $folder; public static function setUpBeforeClass() { // reset backend @@ -89,6 +90,7 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase { // init short data $this->data = 'hats'; $this->filename = 'enc_hooks_tests-' . uniqid() . '.txt'; + $this->folder = 'enc_hooks_tests_folder-' . uniqid(); } @@ -268,4 +270,57 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase { } } + /** + * @brief test rename operation + */ + function testRenameHook() { + + // save file with content + $cryptedFile = file_put_contents('crypt:///' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->filename, $this->data); + + // test that data was successfully written + $this->assertTrue(is_int($cryptedFile)); + + // check if keys exists + $this->assertTrue($this->rootView->file_exists( + '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' + . $this->filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + + $this->assertTrue($this->rootView->file_exists( + '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' + . $this->filename . '.key')); + + // make subfolder + $this->rootView->mkdir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder); + + $this->assertTrue($this->rootView->is_dir('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder)); + + // move the file out of the shared folder + $root = $this->rootView->getRoot(); + $this->rootView->chroot('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/'); + $this->rootView->rename($this->filename, '/' . $this->folder . '/' . $this->filename); + $this->rootView->chroot($root); + + $this->assertFalse($this->rootView->file_exists('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->filename)); + $this->assertTrue($this->rootView->file_exists('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder . '/' . $this->filename)); + + // keys should be renamed too + $this->assertFalse($this->rootView->file_exists( + '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' + . $this->filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + $this->assertFalse($this->rootView->file_exists( + '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' + . $this->filename . '.key')); + + $this->assertTrue($this->rootView->file_exists( + '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/share-keys/' . $this->folder . '/' + . $this->filename . '.' . self::TEST_ENCRYPTION_HOOKS_USER1 . '.shareKey')); + $this->assertTrue($this->rootView->file_exists( + '/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->folder . '/' + . $this->filename . '.key')); + + // cleanup + $this->rootView->unlink('/' . self::TEST_ENCRYPTION_HOOKS_USER1 . '/files/' . $this->folder); + } + } diff --git a/apps/files_encryption/tests/share.php b/apps/files_encryption/tests/share.php index 46a21dd55cd..be56968ac09 100755 --- a/apps/files_encryption/tests/share.php +++ b/apps/files_encryption/tests/share.php @@ -127,6 +127,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { \OC_User::deleteUser(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4); } + /** * @medium * @param bool $withTeardown @@ -498,6 +499,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { } } + function testPublicShareFile() { // login as admin \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); @@ -864,6 +866,13 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { \OCA\Encryption\Helper::adminDisableRecovery('test123'); $this->assertEquals(0, \OC::$server->getAppConfig()->getValue('files_encryption', 'recoveryAdminEnabled')); + + //clean up, reset passwords + \OC_User::setPassword(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, 'test123'); + $params = array('uid' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, + 'password' => \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, + 'recoveryPassword' => 'test123'); + \OCA\Encryption\Hooks::setPassphrase($params); } /** @@ -947,4 +956,65 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase { $this->view->chroot('/'); } + + /** + * @brief test moving a shared file out of the Shared folder + */ + function testRename() { + + // login as admin + \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1); + + // save file with content + $cryptedFile = file_put_contents('crypt:///' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename, $this->dataShort); + + // test that data was successfully written + $this->assertTrue(is_int($cryptedFile)); + + // get the file info from previous created file + $fileInfo = $this->view->getFileInfo( + '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename); + + // check if we have a valid file info + $this->assertTrue($fileInfo instanceof \OC\Files\FileInfo); + + // share the file + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL); + + // check if share key for user2exists + $this->assertTrue($this->view->file_exists( + '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/' + . $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey')); + + + // login as user2 + \Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2); + + $this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename)); + + // get file contents + $retrievedCryptedFile = $this->view->file_get_contents( + '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename); + + // check if data is the same as we previously written + $this->assertEquals($this->dataShort, $retrievedCryptedFile); + + // move the file out of the shared folder + $this->view->rename('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename, + '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + + // check if we can read the moved file + $retrievedRenamedFile = $this->view->file_get_contents( + '/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + + // check if data is the same as we previously written + $this->assertEquals($this->dataShort, $retrievedRenamedFile); + + // the owners file should be deleted + $this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename)); + + // cleanup + $this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename); + } + } -- cgit v1.2.3 From 86b3cdc132a2ae19caf327985d5613a58804d1b5 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 26 Feb 2014 17:18:38 +0100 Subject: close encryption session after decryption was finished --- apps/files_encryption/lib/session.php | 8 ++++++++ apps/files_encryption/lib/util.php | 8 ++++++++ settings/ajax/decryptall.php | 2 ++ 3 files changed, 18 insertions(+) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index aa58e33e9d2..3daaa06425f 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -134,6 +134,14 @@ class Session { } + /** + * @brief remove encryption keys and init status from session + */ + public function closeSession() { + \OC::$session->remove('encryptionInitialized'); + \OC::$session->remove('privateKey'); + } + /** * @brief Gets status if we already tried to initialize the encryption app diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index ec06bd52f5e..6bf69cd8ee1 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -1772,4 +1772,12 @@ class Util { return $session; } + /* + * @brief remove encryption related keys from the session + */ + public function closeEncryptionSession() { + $session = new \OCA\Encryption\Session($this->view); + $session->closeSession(); + } + } diff --git a/settings/ajax/decryptall.php b/settings/ajax/decryptall.php index d7c104ab151..4782a4cfc81 100644 --- a/settings/ajax/decryptall.php +++ b/settings/ajax/decryptall.php @@ -24,6 +24,8 @@ if ($result !== false) { $successful = false; } + $util->closeEncryptionSession(); + if ($successful === true) { \OCP\JSON::success(array('data' => array('message' => 'Files decrypted successfully'))); } else { -- cgit v1.2.3 From 39f2f564a99ebe719748f349aafe92ed9910bc0b Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 27 Feb 2014 09:39:34 +0100 Subject: use assertSame and assertNotSame for etag checks --- apps/files_encryption/tests/util.php | 4 ++-- tests/lib/appframework/http/ResponseTest.php | 2 +- tests/lib/files/cache/scanner.php | 26 ++++++++++++++++++-------- tests/lib/files/etagtest.php | 6 +++++- tests/lib/files/view.php | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php index f70e30c4d73..203ba55dbfd 100755 --- a/apps/files_encryption/tests/util.php +++ b/apps/files_encryption/tests/util.php @@ -344,7 +344,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { // check if mtime and etags unchanged $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); - $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); + $this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); $this->view->unlink($this->userId . '/files/' . $filename); } @@ -373,7 +373,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase { // check if mtime and etags unchanged $this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']); - $this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); + $this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']); // file should no longer be encrypted $this->assertEquals(0, $fileInfoUnencrypted['encrypted']); diff --git a/tests/lib/appframework/http/ResponseTest.php b/tests/lib/appframework/http/ResponseTest.php index 4f21d77a170..063ab8b5d33 100644 --- a/tests/lib/appframework/http/ResponseTest.php +++ b/tests/lib/appframework/http/ResponseTest.php @@ -78,7 +78,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase { public function testGetEtag() { $this->childResponse->setEtag('hi'); - $this->assertEquals('hi', $this->childResponse->getEtag()); + $this->assertSame('hi', $this->childResponse->getEtag()); } diff --git a/tests/lib/files/cache/scanner.php b/tests/lib/files/cache/scanner.php index 3f5604b4d45..9df98c36fa8 100644 --- a/tests/lib/files/cache/scanner.php +++ b/tests/lib/files/cache/scanner.php @@ -150,13 +150,15 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder'), 'storage_mtime' => $this->storage->filemtime('folder'))); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE); $newData = $this->cache->get(''); - $this->assertNotEquals($oldData['etag'], $newData['etag']); + $this->assertTrue(is_string($oldData['etag']), 'Expected a string'); + $this->assertTrue(is_string($newData['etag']), 'Expected a string'); + $this->assertNotSame($oldData['etag'], $newData['etag']); $this->assertEquals($oldData['size'], $newData['size']); $oldData = $newData; $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG); $newData = $this->cache->get(''); - $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertSame($oldData['etag'], $newData['etag']); $this->assertEquals(-1, $newData['size']); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); @@ -164,17 +166,17 @@ class Scanner extends \PHPUnit_Framework_TestCase { $this->assertNotEquals(-1, $oldData['size']); $this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); $newData = $this->cache->get(''); - $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertSame($oldData['etag'], $newData['etag']); $this->assertEquals($oldData['size'], $newData['size']); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); $newData = $this->cache->get(''); - $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertSame($oldData['etag'], $newData['etag']); $this->assertEquals($oldData['size'], $newData['size']); $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE); $newData = $this->cache->get(''); - $this->assertEquals($oldData['etag'], $newData['etag']); + $this->assertSame($oldData['etag'], $newData['etag']); $this->assertEquals($oldData['size'], $newData['size']); } @@ -217,8 +219,11 @@ class Scanner extends \PHPUnit_Framework_TestCase { // manipulate etag to simulate an empty etag $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG); $data0 = $this->cache->get('folder/bar.txt'); + $this->assertTrue(is_string($data0['etag']), 'Expected a string'); $data1 = $this->cache->get('folder'); + $this->assertTrue(is_string($data1['etag']), 'Expected a string'); $data2 = $this->cache->get(''); + $this->assertTrue(is_string($data2['etag']), 'Expected a string'); $data0['etag'] = ''; $this->cache->put('folder/bar.txt', $data0); @@ -227,10 +232,15 @@ class Scanner extends \PHPUnit_Framework_TestCase { // verify cache content $newData0 = $this->cache->get('folder/bar.txt'); + $this->assertTrue(is_string($newData0['etag']), 'Expected a string'); + $this->assertNotEmpty($newData0['etag']); + $newData1 = $this->cache->get('folder'); + $this->assertTrue(is_string($newData1['etag']), 'Expected a string'); + $this->assertNotSame($data1['etag'], $newData1['etag']); + $newData2 = $this->cache->get(''); - $this->assertNotEmpty($newData0['etag']); - $this->assertNotEquals($data1['etag'], $newData1['etag']); - $this->assertNotEquals($data2['etag'], $newData2['etag']); + $this->assertTrue(is_string($newData2['etag']), 'Expected a string'); + $this->assertNotSame($data2['etag'], $newData2['etag']); } } diff --git a/tests/lib/files/etagtest.php b/tests/lib/files/etagtest.php index ce05adb188a..af9f66835f0 100644 --- a/tests/lib/files/etagtest.php +++ b/tests/lib/files/etagtest.php @@ -65,7 +65,11 @@ class EtagTest extends \PHPUnit_Framework_TestCase { $scanner = new \OC\Files\Utils\Scanner($user1); $scanner->backgroundScan('/'); - $this->assertEquals($originalEtags, $this->getEtags($files)); + $newEtags = $this->getEtags($files); + // loop over array and use assertSame over assertEquals to prevent false positives + foreach ($originalEtags as $file => $originalEtag) { + $this->assertSame($originalEtag, $newEtags[$file]); + } } /** diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 371d1ed1798..c85f1128dbe 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -563,6 +563,6 @@ class View extends \PHPUnit_Framework_TestCase { $scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG); $info2 = $view->getFileInfo('/test/test'); - $this->assertEquals($info['etag'], $info2['etag']); + $this->assertSame($info['etag'], $info2['etag']); } } -- cgit v1.2.3 From 4ace1a273d705a21736f92ba3a38f08d8465bca0 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Thu, 27 Feb 2014 13:58:51 +0100 Subject: remember original fopen access type in pre-proxy because sometimes they change during the fopen call, e.g. 'r' becomes 'r+' if we open an URL --- apps/files_encryption/lib/proxy.php | 32 ++++++++++++++++++++++++++------ apps/files_encryption/lib/stream.php | 3 +++ 2 files changed, 29 insertions(+), 6 deletions(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 9d456f6c517..3b9a1f08338 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -38,6 +38,7 @@ class Proxy extends \OC_FileProxy { private static $blackList = null; //mimetypes blacklisted from encryption private static $unencryptedSizes = array(); // remember unencrypted size + private static $fopenMode = array(); // remember the fopen mode /** * Check if a file requires encryption @@ -213,6 +214,16 @@ class Proxy extends \OC_FileProxy { return true; } + /** + * @brief remember initial fopen mode because sometimes it gets changed during the request + * @param string $path path + * @param string $mode type of access + */ + public function preFopen($path, $mode) { + self::$fopenMode[$path] = $mode; + } + + /** * @param $path * @param $result @@ -240,7 +251,15 @@ class Proxy extends \OC_FileProxy { $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - $meta = stream_get_meta_data($result); + // if we remember the mode from the pre proxy we re-use it + // oterwise we fall back to stream_get_meta_data() + if (isset(self::$fopenMode[$path])) { + $mode = self::$fopenMode[$path]; + unset(self::$fopenMode[$path]); + } else { + $meta = stream_get_meta_data($result); + $mode = $meta['mode']; + } $view = new \OC_FilesystemView(''); @@ -258,14 +277,15 @@ class Proxy extends \OC_FileProxy { // Open the file using the crypto stream wrapper // protocol and let it do the decryption work instead - $result = fopen('crypt://' . $path, $meta['mode']); + $result = fopen('crypt://' . $path, $mode); } elseif ( - self::shouldEncrypt($path) - and $meta['mode'] !== 'r' - and $meta['mode'] !== 'rb' + self::shouldEncrypt($path) + and $mode !== 'r' + and $mode !== 'rb' + ) { - $result = fopen('crypt://' . $path, $meta['mode']); + $result = fopen('crypt://' . $path, $mode); } // Re-enable the proxy diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 88eacc6f136..58ac03373a7 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -167,6 +167,9 @@ class Stream { } else { $this->meta = stream_get_meta_data($this->handle); + // sometimes fopen changes the mode, e.g. for a url "r" convert to "r+" + // but we need to remember the original access type + $this->meta['mode'] = $mode; } -- cgit v1.2.3 From fefd7248585e2831adfb1ae9d40c49e94529e36d Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 27 Feb 2014 19:50:16 +0100 Subject: Fixed wrong field name This re-fixes an issue where the unencrypted size isn't updated correctly when saving a text file in the UI multiple times. Fixes #7467 --- apps/files_encryption/lib/proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_encryption') diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 9d456f6c517..6b1e4b7745b 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -146,7 +146,7 @@ class Proxy extends \OC_FileProxy { if ( isset(self::$unencryptedSizes[$normalizedPath]) ) { $view = new \OC_FilesystemView('/'); $view->putFileInfo($normalizedPath, - array('encrypted' => true, 'encrypted_size' => self::$unencryptedSizes[$normalizedPath])); + array('encrypted' => true, 'unencrypted_size' => self::$unencryptedSizes[$normalizedPath])); unset(self::$unencryptedSizes[$normalizedPath]); } -- cgit v1.2.3