]> source.dussan.org Git - nextcloud-server.git/commitdiff
improved file size
authorFlorin Peter <github@florin-peter.de>
Fri, 26 Apr 2013 22:05:20 +0000 (00:05 +0200)
committerFlorin Peter <github@florin-peter.de>
Fri, 26 Apr 2013 22:05:20 +0000 (00:05 +0200)
created new method fixFileSize in Util so it can be used with files_trashbin

apps/files_encryption/lib/proxy.php
apps/files_encryption/lib/util.php

index 73f72a9e23eff70bc3fb9917f1f709aefb491f9d..24821d8a05c901aa4e536b4581bf78d856cee092 100644 (file)
@@ -351,41 +351,7 @@ class Proxy extends \OC_FileProxy {
         $newPathSplit = explode( '/', $newPath );
         $newPathRelative = implode( '/', array_slice( $newPathSplit, 3 ) );
 
-        // get file info from database/cache
-        //$newFileInfo = \OC\Files\Filesystem::getFileInfo($newPathRelative);
-
-        if ($util->isEncryptedPath($newPath)) {
-            $cached = $view->getFileInfo($newPath);
-            $cached['encrypted'] = 1;
-
-            // get the size from filesystem
-            $size = $view->filesize($newPath);
-
-            // calculate last chunk nr
-            $lastChunckNr = floor($size / 8192);
-
-            // open stream
-            $result = fopen('crypt://' . $newPathRelative, "r");
-
-            if(is_resource($result)) {
-                // calculate last chunk position
-                $lastChunckPos = ($lastChunckNr * 8192);
-
-                // seek to end
-                fseek($result, $lastChunckPos);
-
-                // get the content of the last chunck
-                $lastChunkContent = fread($result, 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;
-            }
-
-            $view->putFileInfo( $newPath, $cached );
-
+        if($util->fixFileSize($newPath)) {
             // get sharing app state
             $sharingEnabled = \OCP\Share::isEnabled();
 
@@ -396,13 +362,9 @@ class Proxy extends \OC_FileProxy {
             $util->setSharedFileKeyfiles($session, $usersSharing, $newPathRelative);
         }
 
-
-
-
         \OC_FileProxy::$enabled = $proxyStatus;
 
         return true;
-
     }
 
     public function postFopen( $path, &$result ){
index 2198963ce14ef2bb0abc87fc17fece24d495f44d..9d9e420e4d3f5e4c2f78fabf5ea274d5520b4261 100644 (file)
@@ -421,10 +421,10 @@ class Util {
                return $text;
        }
        
-        /**
-         * @brief Check if a given path identifies an encrypted file
-         * @return true / false
-         */
+    /**
+     * @brief Check if a given path identifies an encrypted file
+     * @return true / false
+     */
        public function isEncryptedPath( $path ) {
        
                // Disable encryption proxy so data retreived is in its 
@@ -438,7 +438,67 @@ class Util {
                return Crypt::isCatfileContent( $data );
        
        }
-       
+
+    /**
+     * @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;
+
+        if ($this->isEncryptedPath($path)) {
+
+            // Reformat path for use with OC_FSV
+            $pathSplit = explode( '/', $path );
+            $pathRelative = implode( '/', array_slice( $pathSplit, 3 ) );
+
+            $cached = $this->view->getFileInfo($path);
+            $cached['encrypted'] = 1;
+
+            // get the size from filesystem
+            $size = $this->view->filesize($path);
+
+            // calculate last chunk nr
+            $lastChunckNr = floor($size / 8192);
+
+            // open stream
+            $result = fopen('crypt://' . $pathRelative, "r");
+
+            if(is_resource($result)) {
+                // calculate last chunk position
+                $lastChunckPos = ($lastChunckNr * 8192);
+
+                // seek to end
+                fseek($result, $lastChunckPos);
+
+                // get the content of the last chunk
+                $lastChunkContent = fread($result, 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;
+            }
+
+            // put file info
+            $this->view->putFileInfo( $path, $cached );
+
+            $result = true;
+        }
+
+        \OC_FileProxy::$enabled = $proxyStatus;
+
+        return $result;
+    }
+
        /**
         * @brief Format a path to be relative to the /user/files/ directory
         */