diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-03-30 22:45:58 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:28 +0200 |
commit | 1b42b492dce562596b8b57a11546728f697c4f38 (patch) | |
tree | 6280aa40baaf55db44edf84a906b83db2d47fc46 | |
parent | dbdd754c3fc37dc3100a9741f956d913e6d64576 (diff) | |
download | nextcloud-server-1b42b492dce562596b8b57a11546728f697c4f38.tar.gz nextcloud-server-1b42b492dce562596b8b57a11546728f697c4f38.zip |
kill OC_FileProxy :boom:
-rw-r--r-- | apps/encryption/lib/keymanager.php | 6 | ||||
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 27 | ||||
-rw-r--r-- | apps/files_versions/lib/storage.php | 14 | ||||
-rw-r--r-- | lib/private/cache/file.php | 9 | ||||
-rw-r--r-- | lib/private/filechunking.php | 4 | ||||
-rw-r--r-- | lib/private/fileproxy.php | 138 | ||||
-rw-r--r-- | lib/private/files/view.php | 22 | ||||
-rw-r--r-- | lib/private/server.php | 12 | ||||
-rw-r--r-- | tests/bootstrap.php | 1 | ||||
-rw-r--r-- | tests/lib/cache/file.php | 1 | ||||
-rw-r--r-- | tests/lib/cache/usercache.php | 1 | ||||
-rw-r--r-- | tests/lib/testcase.php | 11 |
12 files changed, 6 insertions, 240 deletions
diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php index 68fb722c5ea..d9b670c3f5a 100644 --- a/apps/encryption/lib/keymanager.php +++ b/apps/encryption/lib/keymanager.php @@ -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; } } } diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 6bdbac49aa7..8d352e36311 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -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; } } diff --git a/apps/files_versions/lib/storage.php b/apps/files_versions/lib/storage.php index 01a7935c0c5..125fb5d983c 100644 --- a/apps/files_versions/lib/storage.php +++ b/apps/files_versions/lib/storage.php @@ -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; } diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php index 8874acbb1e5..c70698eb7f8 100644 --- a/lib/private/cache/file.php +++ b/lib/private/cache/file.php @@ -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; } diff --git a/lib/private/filechunking.php b/lib/private/filechunking.php index e8a58b2538d..82bf61fa7b1 100644 --- a/lib/private/filechunking.php +++ b/lib/private/filechunking.php @@ -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 index 8b28e866ac2..00000000000 --- a/lib/private/fileproxy.php +++ /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(); - } -} diff --git a/lib/private/files/view.php b/lib/private/files/view.php index f8ec4a0eb43..0f371bbc5ea 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -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); } diff --git a/lib/private/server.php b/lib/private/server.php index d9c580c0f0c..d135150c1f7 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -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); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index cebd899e785..5945dbdc11f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -25,4 +25,3 @@ if (!class_exists('PHPUnit_Framework_TestCase')) { OC_Hook::clear(); OC_Log::$enabled = false; -OC_FileProxy::clearProxies(); diff --git a/tests/lib/cache/file.php b/tests/lib/cache/file.php index 1bf7491081d..153cb198f13 100644 --- a/tests/lib/cache/file.php +++ b/tests/lib/cache/file.php @@ -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 diff --git a/tests/lib/cache/usercache.php b/tests/lib/cache/usercache.php index 63667a3d34e..26a9158ab3a 100644 --- a/tests/lib/cache/usercache.php +++ b/tests/lib/cache/usercache.php @@ -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 diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index d532a3b01c0..a83be713194 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -71,7 +71,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { self::tearDownAfterClassCleanFileCache(); self::tearDownAfterClassCleanStrayDataFiles($dataDir); self::tearDownAfterClassCleanStrayHooks(); - self::tearDownAfterClassCleanProxies(); parent::tearDownAfterClass(); } @@ -165,16 +164,6 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { } /** - * 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. * |