]> source.dussan.org Git - nextcloud-server.git/commitdiff
speed improvement
authorFlorin Peter <github@florin-peter.de>
Sun, 28 Apr 2013 23:43:59 +0000 (01:43 +0200)
committerFlorin Peter <github@florin-peter.de>
Sun, 28 Apr 2013 23:43:59 +0000 (01:43 +0200)
apps/files_encryption/lib/stream.php

index 411bcdac92d7200c3ed44b93fd951fbea2d98693..a51f2c56d953f75fa5dc5746dca64d29502192ce 100644 (file)
@@ -298,7 +298,8 @@ class Stream {
                // automatically attempted when the file is written to disk - 
                // we are handling that separately here and we don't want to 
                // get into an infinite loop
-               //\OC_FileProxy::$enabled = false;
+        $proxyStatus = \OC_FileProxy::$enabled;
+               \OC_FileProxy::$enabled = false;
                
                // Get the length of the unencrypted data that we are handling
                $length = strlen( $data );
@@ -322,30 +323,7 @@ class Stream {
                        
                }
                
-               // Fetch user's public key
-               $this->publicKey = Keymanager::getPublicKey( $this->rootView, $this->userId );
-               
-               // Check if OC sharing api is enabled
-               $sharingEnabled = \OCP\Share::isEnabled();
-               
-               $util = new Util( $this->rootView, $this->userId );
-               
-               // Get all users sharing the file includes current user
-               $uniqueUserIds = $util->getSharingUsersArray( $sharingEnabled, $this->relPath, $this->userId);
-
-        // Fetch public keys for all sharing users
-               $publicKeys = Keymanager::getPublicKeys( $this->rootView, $uniqueUserIds );
 
-        // Encrypt enc key for all sharing users
-               $this->encKeyfiles = Crypt::multiKeyEncrypt( $this->plainKey, $publicKeys );
-               
-               $view = new \OC_FilesystemView( '/' );
-               
-               // Save the new encrypted file key
-               Keymanager::setFileKey( $this->rootView, $this->relPath, $this->userId, $this->encKeyfiles['data'] );
-               
-               // Save the sharekeys
-               Keymanager::setShareKeys( $view, $this->relPath, $this->encKeyfiles['keys'] );
                
                // If extra data is left over from the last round, make sure it 
                // is integrated into the next 6126 / 8192 block
@@ -437,6 +415,8 @@ class Stream {
                $this->size = max( $this->size, $pointer + $length );
         $this->unencryptedSize += $length;
 
+        \OC_FileProxy::$enabled = $proxyStatus;
+
                return $length;
 
        }
@@ -492,13 +472,46 @@ class Stream {
        }
 
        public function stream_close() {
-       
-               $this->flush();
+
+        $this->flush();
                
                if ( 
                $this->meta['mode']!='r' 
                and $this->meta['mode']!='rb' 
                ) {
+
+            // Disable encryption proxy to prevent recursive calls
+            $proxyStatus = \OC_FileProxy::$enabled;
+            \OC_FileProxy::$enabled = false;
+
+            // Fetch user's public key
+            $this->publicKey = Keymanager::getPublicKey( $this->rootView, $this->userId );
+
+            // Check if OC sharing api is enabled
+            $sharingEnabled = \OCP\Share::isEnabled();
+
+            $util = new Util( $this->rootView, $this->userId );
+
+            // Get all users sharing the file includes current user
+            $uniqueUserIds = $util->getSharingUsersArray( $sharingEnabled, $this->relPath, $this->userId);
+
+            // Fetch public keys for all sharing users
+            $publicKeys = Keymanager::getPublicKeys( $this->rootView, $uniqueUserIds );
+
+            // Encrypt enc key for all sharing users
+            $this->encKeyfiles = Crypt::multiKeyEncrypt( $this->plainKey, $publicKeys );
+
+            $view = new \OC_FilesystemView( '/' );
+
+            // Save the new encrypted file key
+            Keymanager::setFileKey( $this->rootView, $this->relPath, $this->userId, $this->encKeyfiles['data'] );
+
+            // Save the sharekeys
+            Keymanager::setShareKeys( $view, $this->relPath, $this->encKeyfiles['keys'] );
+
+            // Re-enable proxy - our work is done
+            \OC_FileProxy::$enabled = $proxyStatus;
+
                        \OC\Files\Filesystem::putFileInfo( $this->relPath, array( 'encrypted' => 1, 'size' => $this->size, 'unencrypted_size' => $this->unencryptedSize ), '' );
                }