From 0e1970438b6dd7b6f705aeb420e1d4b4bd27c609 Mon Sep 17 00:00:00 2001 From: Florin Peter Date: Thu, 18 Apr 2013 22:34:22 +0200 Subject: [PATCH] fixed incorrect filesize, download via web is now possible fixed broken file-info --- apps/files_encryption/lib/proxy.php | 36 ++++++++++++++++++++++++++-- apps/files_encryption/lib/stream.php | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 3af9dc73d83..e23598bb5ff 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -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']; diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php index 01eee177cd9..4b33c200bf3 100644 --- a/apps/files_encryption/lib/stream.php +++ b/apps/files_encryption/lib/stream.php @@ -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 ), '' ); } -- 2.39.5