From: Florin Peter Date: Sat, 27 Apr 2013 21:34:25 +0000 (+0200) Subject: improved file size X-Git-Tag: v6.0.0alpha2~743^2~146 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f9760f65212bd6464685ec1dd60a73825b4a3f66;p=nextcloud-server.git improved file size --- diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index a9996999a3a..fe040d88775 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -440,53 +440,78 @@ class Util { } /** - * @brief fix the file size of the encrypted file + * @brief get the file size of the unencrypted file * * @param $path absolute path * @return true / false if file is encrypted */ - public function fixFileSize($path) { - $result = false; + public function getFileSize($path) { + $result = 0; // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; - if ($this->view->file_exists($path) && $this->isEncryptedPath($path)) { - - // Reformat path for use with OC_FSV - $pathSplit = explode( '/', $path ); - $pathRelative = implode( '/', array_slice( $pathSplit, 3 ) ); + // Reformat path for use with OC_FSV + $pathSplit = explode( '/', $path ); + $pathRelative = implode( '/', array_slice( $pathSplit, 3 ) ); - $cached = $this->view->getFileInfo($path); - $cached['encrypted'] = 1; + if ($pathSplit[2] == 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) { // get the size from filesystem - $size = $this->view->filesize($path); + $fullPath = $this->view->getLocalFile($path); + $size = filesize($fullPath); // calculate last chunk nr $lastChunckNr = floor($size / 8192); // open stream - $result = fopen('crypt://' . $pathRelative, "r"); + $stream = fopen('crypt://' . $pathRelative, "r"); - if(is_resource($result)) { + if(is_resource($stream)) { // calculate last chunk position $lastChunckPos = ($lastChunckNr * 8192); // seek to end - fseek($result, $lastChunckPos); + fseek($stream, $lastChunckPos); // get the content of the last chunk - $lastChunkContent = fread($result, 8192); + $lastChunkContent = fread($stream, 8192); // calc the real file size with the size of the last chunk $realSize = (($lastChunckNr * 6126) + strlen($lastChunkContent)); - // set the size - $cached['unencrypted_size'] = $realSize; + // store file size + $result = $realSize; } + } + + \OC_FileProxy::$enabled = $proxyStatus; + + return $result; + } + /** + * @brief fix the file size of the encrypted file + * + * @param $path absolute path + * @return true / false if file is encrypted + */ + + public function fixFileSize($path) { + $result = false; + + // Disable encryption proxy to prevent recursive calls + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; + + $realSize = $this->getFileSize($path); + if($realSize > 0) { + $cached = $this->view->getFileInfo($path); + $cached['encrypted'] = 1; + + // set the size + $cached['unencrypted_size'] = $realSize; // put file info $this->view->putFileInfo( $path, $cached );