]> source.dussan.org Git - nextcloud-server.git/commitdiff
try to fix unencrypted file size if it doesn't look plausible
authorBjoern Schiessle <schiessle@owncloud.com>
Mon, 14 Oct 2013 14:34:14 +0000 (16:34 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Mon, 14 Oct 2013 14:34:14 +0000 (16:34 +0200)
apps/files_encryption/lib/proxy.php

index 8621c1ba51d6199dc8c49f46a06fa1ed3cc35c03..f8d10bdcd8b7c30eb56513fdc52040d2fe9c32bb 100644 (file)
@@ -316,6 +316,16 @@ class Proxy extends \OC_FileProxy {
 
                $view = new \OC_FilesystemView('/');
 
+               $userId = \OCP\User::getUser();
+               $util = new Util($view, $userId);
+
+               // if encryption is no longer enabled or if the files aren't migrated yet
+               // we return the default file size
+               if(!\OCP\App::isEnabled('files_encryption') ||
+                               $util->getMigrationStatus() !== Util::MIGRATION_COMPLETED) {
+                       return $size;
+               }
+
                // if path is a folder do nothing
                if ($view->is_dir($path)) {
                        return $size;
@@ -337,6 +347,15 @@ class Proxy extends \OC_FileProxy {
 
                // if file is encrypted return real file size
                if (is_array($fileInfo) && $fileInfo['encrypted'] === true) {
+                       // try to fix unencrypted file size if it doesn't look plausible
+                       if ((int)$fileInfo['size'] > 0 && (int)$fileInfo['encrypted_size'] === 0) {
+                               $fixSize = $util->getFileSize($path);
+                               $fileInfo['unencrypted_size'] = $fixSize;
+                               // put file info if not .part file
+                               if (!Keymanager::isPartialFilePath($relativePath)) {
+                                       $view->putFileInfo($path, $fileInfo);
+                               }
+                       }
                        $size = $fileInfo['unencrypted_size'];
                } else {
                        // self healing if file was removed from file cache
@@ -344,8 +363,6 @@ class Proxy extends \OC_FileProxy {
                                $fileInfo = array();
                        }
 
-                       $userId = \OCP\User::getUser();
-                       $util = new Util($view, $userId);
                        $fixSize = $util->getFileSize($path);
                        if ($fixSize > 0) {
                                $size = $fixSize;