]> source.dussan.org Git - nextcloud-server.git/commitdiff
fixed incorrect filesize, download via web is now possible
authorFlorin Peter <github@florin-peter.de>
Thu, 18 Apr 2013 20:34:22 +0000 (22:34 +0200)
committerFlorin Peter <github@florin-peter.de>
Thu, 18 Apr 2013 20:34:22 +0000 (22:34 +0200)
fixed broken file-info

apps/files_encryption/lib/proxy.php
apps/files_encryption/lib/stream.php

index 3af9dc73d83610dff4dde8b6bf3443422bd94ceb..e23598bb5ffb8099b4303e74cc19cc974d591b94 100644 (file)
@@ -439,9 +439,41 @@ class Proxy extends \OC_FileProxy {
 
        public function postFileSize( $path, $size ) {
                
-               if ( Crypt::isCatfileContent( $path ) ) {
+               // Reformat path for use with OC_FSV
+               $path_split = explode( '/', $path );
+               $path_f = implode( '/', array_slice( $path_split, 3 ) );
+               
+               if ( Crypt::isEncryptedMeta( $path_f ) ) {
                        
-                       $cached = \OC\Files\Filesystem::getFileInfo( $path, '' );
+                       // Disable encryption proxy to prevent recursive calls
+                       \OC_FileProxy::$enabled = false;
+                               
+                       // get file info
+                       $cached = \OC\Files\Filesystem::getFileInfo( $path_f, '' );
+                       
+                       // calculate last chunk nr
+                       $lastChunckNr = floor( $size / 8192);
+                       
+                       // open stream
+                       $result = fopen( 'crypt://'.$path_f, "r" );
+                       
+                       // calculate last chunk position
+                       $lastChunckPos = ( $lastChunckNr * 8192 );
+                       
+                       // seek to end
+                       fseek( $result, $lastChunckPos );
+                       
+                       // get the content of the last chunck
+                       $lastChunkContent = fgets( $result );
+                       
+                       // calc the real filesize with the size of the last chunk
+                       $realSize = ( ( $lastChunckNr * 6126 ) + strlen( $lastChunkContent ) );
+                       
+                       // enable proxy
+                       \OC_FileProxy::$enabled = true;
+                       
+                       // set the size
+                       $cached['size'] = $realSize;
                        
                        return  $cached['size'];
                
index 01eee177cd9de2a037a44b9d997a57630fbf5f16..4b33c200bf38a82b19fc2b5c458cd5fd4b8b4c0a 100644 (file)
@@ -513,7 +513,7 @@ class Stream {
                and $this->meta['mode']!='rb' 
                ) {
                        
-                       \OC\Files\Filesystem::putFileInfo( $this->path, array( 'encrypted' => true, 'size' => $this->size ), '' );
+                       \OC\Files\Filesystem::putFileInfo( $this->relPath, array( 'encrypted' => true, 'size' => $this->size ), '' );
 
                }