]> source.dussan.org Git - nextcloud-server.git/commitdiff
kill OC_FileProxy :boom:
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 30 Mar 2015 20:45:58 +0000 (22:45 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:28 +0000 (13:30 +0200)
12 files changed:
apps/encryption/lib/keymanager.php
apps/files_trashbin/lib/trashbin.php
apps/files_versions/lib/storage.php
lib/private/cache/file.php
lib/private/filechunking.php
lib/private/fileproxy.php [deleted file]
lib/private/files/view.php
lib/private/server.php
tests/bootstrap.php
tests/lib/cache/file.php
tests/lib/cache/usercache.php
tests/lib/testcase.php

index 68fb722c5eaa62a1da337bc85e67b253919b49f5..d9b670c3f5a832c506b0f6149786c9a9e561dec2 100644 (file)
@@ -375,10 +375,6 @@ class KeyManager {
 
                                $keyPair = $this->crypt->createKeyPair();
 
-                               // Disable encryption proxy to prevent recursive calls
-                               $proxyStatus = \OC_FileProxy::$enabled;
-                               \OC_FileProxy::$enabled = false;
-
                                // Save public key
                                $this->setPublicKey($user, $keyPair['publicKey']);
 
@@ -395,8 +391,6 @@ class KeyManager {
                                } else {
                                        $this->log->error('Encryption Could not update users encryption password');
                                }
-
-                               \OC_FileProxy::$enabled = $proxyStatus;
                        }
                }
        }
index 6bdbac49aa707642503daef161526a9967fdd026..8d352e363112bd427e08e8ab6416f4772355b993 100644 (file)
@@ -183,8 +183,6 @@ class Trashbin {
                $userTrashSize = self::getTrashbinSize($user);
 
                // disable proxy to prevent recursive calls
-               $proxyStatus = \OC_FileProxy::$enabled;
-               \OC_FileProxy::$enabled = false;
                $trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
                try {
                        $sizeOfAddedFiles = $view->filesize('/files/' . $file_path);
@@ -199,7 +197,6 @@ class Trashbin {
                        }
                        \OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
                }
-               \OC_FileProxy::$enabled = $proxyStatus;
 
                if ($view->file_exists('/files/' . $file_path)) { // failed to delete the original file, abort
                        $view->unlink($trashPath);
@@ -251,10 +248,6 @@ class Trashbin {
                $size = 0;
                if (\OCP\App::isEnabled('files_versions')) {
 
-                       // disable proxy to prevent recursive calls
-                       $proxyStatus = \OC_FileProxy::$enabled;
-                       \OC_FileProxy::$enabled = false;
-
                        $user = \OCP\User::getUser();
                        $rootView = new \OC\Files\View('/');
 
@@ -279,9 +272,6 @@ class Trashbin {
                                        $rootView->rename($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp);
                                }
                        }
-
-                       // enable proxy
-                       \OC_FileProxy::$enabled = $proxyStatus;
                }
 
                return $size;
@@ -369,10 +359,6 @@ class Trashbin {
                $target = \OC\Files\Filesystem::normalizePath('files/' . $location . '/' . $uniqueFilename);
                $mtime = $view->filemtime($source);
 
-               // disable proxy to prevent recursive calls
-               $proxyStatus = \OC_FileProxy::$enabled;
-               \OC_FileProxy::$enabled = false;
-
                // restore file
                $restoreResult = $view->rename($source, $target);
 
@@ -393,15 +379,9 @@ class Trashbin {
                                $query->execute(array($user, $filename, $timestamp));
                        }
 
-                       // enable proxy
-                       \OC_FileProxy::$enabled = $proxyStatus;
-
                        return true;
                }
 
-               // enable proxy
-               \OC_FileProxy::$enabled = $proxyStatus;
-
                return false;
        }
 
@@ -419,9 +399,6 @@ class Trashbin {
        private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
 
                if (\OCP\App::isEnabled('files_versions')) {
-                       // disable proxy to prevent recursive calls
-                       $proxyStatus = \OC_FileProxy::$enabled;
-                       \OC_FileProxy::$enabled = false;
 
                        $user = \OCP\User::getUser();
                        $rootView = new \OC\Files\View('/');
@@ -432,7 +409,6 @@ class Trashbin {
 
                        // file has been deleted in between
                        if (empty($ownerPath)) {
-                               \OC_FileProxy::$enabled = $proxyStatus;
                                return false;
                        }
 
@@ -453,9 +429,6 @@ class Trashbin {
                                        }
                                }
                        }
-
-                       // enable proxy
-                       \OC_FileProxy::$enabled = $proxyStatus;
                }
        }
 
index 01a7935c0c5a4c48820d8b75424e3ce0a2c851f7..125fb5d983c8b2564553b2590c5e72e3462eccb7 100644 (file)
@@ -160,18 +160,11 @@ class Storage {
 
                        self::scheduleExpire($filename, $versionsSize, $neededSpace);
 
-                       // disable proxy to prevent multiple fopen calls
-                       $proxyStatus = \OC_FileProxy::$enabled;
-                       \OC_FileProxy::$enabled = false;
-
                        // store a new version of a file
                        $mtime = $users_view->filemtime('files/' . $filename);
                        $users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime);
                        // call getFileInfo to enforce a file cache entry for the new version
                        $users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
-
-                       // reset proxy state
-                       \OC_FileProxy::$enabled = $proxyStatus;
                }
        }
 
@@ -283,15 +276,8 @@ class Storage {
                        $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
                        if ( !$users_view->file_exists($version)) {
 
-                               // disable proxy to prevent multiple fopen calls
-                               $proxyStatus = \OC_FileProxy::$enabled;
-                               \OC_FileProxy::$enabled = false;
-
                                $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
 
-                               // reset proxy state
-                               \OC_FileProxy::$enabled = $proxyStatus;
-
                                $versionCreated = true;
                        }
 
index 8874acbb1e5aba613b856122e38fba03846937e4..c70698eb7f878a06fc90453e2c0869ba9028bbfc 100644 (file)
@@ -67,13 +67,10 @@ class File {
         */
        public function get($key) {
                $result = null;
-               $proxyStatus = \OC_FileProxy::$enabled;
-               \OC_FileProxy::$enabled = false;
                if ($this->hasKey($key)) {
                        $storage = $this->getStorage();
                        $result = $storage->file_get_contents($key);
                }
-               \OC_FileProxy::$enabled = $proxyStatus;
                return $result;
        }
 
@@ -85,13 +82,10 @@ class File {
         */
        public function size($key) {
                $result = 0;
-               $proxyStatus = \OC_FileProxy::$enabled;
-               \OC_FileProxy::$enabled = false;
                if ($this->hasKey($key)) {
                        $storage = $this->getStorage();
                        $result = $storage->filesize($key);
                }
-               \OC_FileProxy::$enabled = $proxyStatus;
                return $result;
        }
 
@@ -101,7 +95,6 @@ class File {
        public function set($key, $value, $ttl = 0) {
                $storage = $this->getStorage();
                $result = false;
-               $proxyStatus = \OC_FileProxy::$enabled;
                // unique id to avoid chunk collision, just in case
                $uniqueId = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
                        16,
@@ -111,7 +104,6 @@ class File {
                // use part file to prevent hasKey() to find the key
                // while it is being written
                $keyPart = $key . '.' . $uniqueId . '.part';
-               \OC_FileProxy::$enabled = false;
                if ($storage and $storage->file_put_contents($keyPart, $value)) {
                        if ($ttl === 0) {
                                $ttl = 86400; // 60*60*24
@@ -119,7 +111,6 @@ class File {
                        $result = $storage->touch($keyPart, time() + $ttl);
                        $result &= $storage->rename($keyPart, $key);
                }
-               \OC_FileProxy::$enabled = $proxyStatus;
                return $result;
        }
 
index e8a58b2538d6e2dcc88ce16a6e5f3783053f3544..82bf61fa7b141cc7f831f7a5908e4a5a92dc9e6c 100644 (file)
@@ -189,8 +189,7 @@ class OC_FileChunking {
                $absolutePath = \OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getView()->getAbsolutePath($path));
                $data = '';
                // use file_put_contents as method because that best matches what this function does
-               if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
-                       && \OC\Files\Filesystem::isValidPath($path)) {
+               if (\OC\Files\Filesystem::isValidPath($path)) {
                        $path = \OC\Files\Filesystem::getView()->getRelativePath($absolutePath);
                        $exists = \OC\Files\Filesystem::file_exists($path);
                        $run = true;
@@ -231,7 +230,6 @@ class OC_FileChunking {
                                        \OC\Files\Filesystem::signal_post_write,
                                        array( \OC\Files\Filesystem::signal_param_path => $path)
                                );
-                               OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
                                return $count > 0;
                        }else{
                                return false;
diff --git a/lib/private/fileproxy.php b/lib/private/fileproxy.php
deleted file mode 100644 (file)
index 8b28e86..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-<?php
-/**
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Felix Moeller <mail@felixmoeller.de>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
- * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/**
- * Class for manipulating filesystem requests
- *
- * Manipulation happens by using 2 kind of proxy operations, pre and post proxies
- * that manipulate the filesystem call and the result of the call respectively
- *
- * A pre-proxy recieves the filepath as arugments (or 2 filespaths in case of
- * operations like copy or move) and return a boolean
- * If a pre-proxy returns false the file operation will be canceled
- * All filesystem operations have a pre-proxy
- *
- * A post-proxy recieves 2 arguments, the filepath and the result of the operation.
- * The return value of the post-proxy will be used as the new result of the operation
- * The operations that have a post-proxy are:
- * file_get_contents, is_file, is_dir, file_exists, stat, is_readable,
- * is_writable, filemtime, filectime, file_get_contents,
- * getMimeType, hash, fopen, free_space and search
- */
-
-class OC_FileProxy{
-       private static $proxies=array();
-       public static $enabled=true;
-
-       /**
-        * fallback function when a proxy operation is not implemented
-        * @param string $function the name of the proxy operation
-        * @param mixed $arguments
-        *
-        * this implements a dummy proxy for all operations
-        */
-       public function __call($function, $arguments) {
-               if(substr($function, 0, 3)=='pre') {
-                       return true;
-               }else{
-                       return $arguments[1];
-               }
-       }
-
-       /**
-        * register a proxy to be used
-        * @param OC_FileProxy $proxy
-        */
-       public static function register($proxy) {
-               self::$proxies[]=$proxy;
-       }
-
-       /**
-        * @param string $operation
-        */
-       public static function getProxies($operation = null) {
-               if ($operation === null) {
-                       // return all
-                       return self::$proxies;
-               }
-               $proxies=array();
-               foreach(self::$proxies as $proxy) {
-                       if(method_exists($proxy, $operation)) {
-                               $proxies[]=$proxy;
-                       }
-               }
-               return $proxies;
-       }
-
-       /**
-        * @param string $operation
-        * @param string|boolean $filepath
-        */
-       public static function runPreProxies($operation,&$filepath,&$filepath2=null) {
-               if(!self::$enabled) {
-                       return true;
-               }
-               $operation='pre'.$operation;
-               $proxies=self::getProxies($operation);
-               foreach($proxies as $proxy) {
-                       if(!is_null($filepath2)) {
-                               if($proxy->$operation($filepath, $filepath2)===false) {
-                                       return false;
-                               }
-                       }else{
-                               if($proxy->$operation($filepath)===false) {
-                                       return false;
-                               }
-                       }
-               }
-               return true;
-       }
-
-       /**
-        * @param string $operation
-        * @param string|boolean $path
-        *
-        * @return string
-        */
-       public static function runPostProxies($operation, $path, $result) {
-               if(!self::$enabled) {
-                       return $result;
-               }
-               $operation='post'.$operation;
-               $proxies=self::getProxies($operation);
-               foreach($proxies as $proxy) {
-                       $result=$proxy->$operation($path, $result);
-               }
-               return $result;
-       }
-
-       public static function clearProxies() {
-               self::$proxies=array();
-       }
-}
index f8ec4a0eb43c1b2fb25ea8ba0400ca2ca52e0e0d..0f371bbc5eacd2c69cb85c50c68fd684d2e7abe6 100644 (file)
@@ -515,8 +515,7 @@ class View {
        public function file_put_contents($path, $data) {
                if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
                        $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
-                       if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
-                               and Filesystem::isValidPath($path)
+                       if (Filesystem::isValidPath($path)
                                and !Filesystem::isFileBlacklisted($path)
                        ) {
                                $path = $this->getRelativePath($absolutePath);
@@ -537,7 +536,6 @@ class View {
                                        if ($this->shouldEmitHooks($path) && $result !== false) {
                                                $this->emit_file_hooks_post($exists, $path);
                                        }
-                                       \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
                                        return $result;
                                } else {
                                        return false;
@@ -591,8 +589,7 @@ class View {
                $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
                $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
                if (
-                       \OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
-                       and Filesystem::isValidPath($path2)
+                       Filesystem::isValidPath($path2)
                        and Filesystem::isValidPath($path1)
                        and !Filesystem::isFileBlacklisted($path2)
                ) {
@@ -635,14 +632,12 @@ class View {
                                                $sourceMountPoint = $mount->getMountPoint();
                                                $result = $mount->moveMount($absolutePath2);
                                                $manager->moveMount($sourceMountPoint, $mount->getMountPoint());
-                                               \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
                                        } else {
                                                $result = false;
                                        }
                                } elseif ($mp1 == $mp2) {
                                        if ($storage1) {
                                                $result = $storage1->rename($internalPath1, $internalPath2);
-                                               \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
                                        } else {
                                                $result = false;
                                        }
@@ -718,8 +713,7 @@ class View {
                $absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
                $absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
                if (
-                       \OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
-                       and Filesystem::isValidPath($path2)
+                       Filesystem::isValidPath($path2)
                        and Filesystem::isValidPath($path1)
                        and !Filesystem::isFileBlacklisted($path2)
                ) {
@@ -927,7 +921,7 @@ class View {
        public function hash($type, $path, $raw = false) {
                $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
                $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
-               if (\OC_FileProxy::runPreProxies('hash', $absolutePath) && Filesystem::isValidPath($path)) {
+               if (Filesystem::isValidPath($path)) {
                        $path = $this->getRelativePath($absolutePath);
                        if ($path == null) {
                                return false;
@@ -942,7 +936,6 @@ class View {
                        list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
                        if ($storage) {
                                $result = $storage->hash($type, $internalPath, $raw);
-                               $result = \OC_FileProxy::runPostProxies('hash', $absolutePath, $result);
                                return $result;
                        }
                }
@@ -975,8 +968,7 @@ class View {
        private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) {
                $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
                $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
-               if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
-                       and Filesystem::isValidPath($path)
+               if (Filesystem::isValidPath($path)
                        and !Filesystem::isFileBlacklisted($path)
                ) {
                        $path = $this->getRelativePath($absolutePath);
@@ -993,8 +985,6 @@ class View {
                                        $result = $storage->$operation($internalPath);
                                }
 
-                               $result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
-
                                if (in_array('delete', $hooks) and $result) {
                                        $this->updater->remove($path);
                                }
@@ -1168,8 +1158,6 @@ class View {
                        $data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
                }
 
-               $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
-
                return new FileInfo($path, $storage, $internalPath, $data, $mount);
        }
 
index d9c580c0f0cb11a3c127e4f5e2e0eb74c97f1708..d135150c1f771996c54ec216d85323da7127d0ad 100644 (file)
@@ -496,19 +496,7 @@ class Server extends SimpleContainer implements IServerContainer {
                $dir = '/files';
                if (!$folder->nodeExists($dir)) {
                        $folder = $folder->newFolder($dir);
-
-                       if (\OCP\App::isEnabled('files_encryption')) {
-                               // disable encryption proxy to prevent recursive calls
-                               $proxyStatus = \OC_FileProxy::$enabled;
-                               \OC_FileProxy::$enabled = false;
-                       }
-
                        \OC_Util::copySkeleton($user, $folder);
-
-                       if (\OCP\App::isEnabled('files_encryption')) {
-                               // re-enable proxy - our work is done
-                               \OC_FileProxy::$enabled = $proxyStatus;
-                       }
                } else {
                        $folder = $folder->get($dir);
                }
index cebd899e785443ecdfcfc1efc7b462ed5fae7b84..5945dbdc11fdc77b3e5d2644a8544f0e5adcb576 100644 (file)
@@ -25,4 +25,3 @@ if (!class_exists('PHPUnit_Framework_TestCase')) {
 
 OC_Hook::clear();
 OC_Log::$enabled = false;
-OC_FileProxy::clearProxies();
index 1bf7491081d138f600f7ca8f74e790bd9740ee0f..153cb198f13b961649f595d6280f82f9c99c83b6 100644 (file)
@@ -38,7 +38,6 @@ class FileCache extends \Test_Cache {
                parent::setUp();
 
                //clear all proxies and hooks so we can do clean testing
-               \OC_FileProxy::clearProxies();
                \OC_Hook::clear('OC_Filesystem');
 
                //set up temporary storage
index 63667a3d34e2d4d2bd44bcecf406d9b2f6086fbc..26a9158ab3aad48d9e213af340618c86bfdc2b86 100644 (file)
@@ -34,7 +34,6 @@ class UserCache extends \Test_Cache {
                parent::setUp();
 
                //clear all proxies and hooks so we can do clean testing
-               \OC_FileProxy::clearProxies();
                \OC_Hook::clear('OC_Filesystem');
 
                //set up temporary storage
index d532a3b01c0944be2795c0e5d159ea28f723ca76..a83be713194a91ca6c331889fbd57edce283645f 100644 (file)
@@ -71,7 +71,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
                self::tearDownAfterClassCleanFileCache();
                self::tearDownAfterClassCleanStrayDataFiles($dataDir);
                self::tearDownAfterClassCleanStrayHooks();
-               self::tearDownAfterClassCleanProxies();
 
                parent::tearDownAfterClass();
        }
@@ -164,16 +163,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
                \OC_Hook::clear();
        }
 
-       /**
-        * Clean up the list of file proxies
-        *
-        * Also reenables file proxies, in case a test disabled them
-        */
-       static protected function tearDownAfterClassCleanProxies() {
-               \OC_FileProxy::$enabled = true;
-               \OC_FileProxy::clearProxies();
-       }
-
        /**
         * Login and setup FS as a given user,
         * sets the given user as the current user.