diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/db.php | 7 | ||||
-rw-r--r-- | lib/private/db/connectionfactory.php | 7 | ||||
-rw-r--r-- | lib/private/db/mdb2schemamanager.php | 2 | ||||
-rw-r--r-- | lib/private/files.php | 2 | ||||
-rw-r--r-- | lib/private/files/mount/manager.php | 2 | ||||
-rw-r--r-- | lib/private/files/storage/local.php | 21 | ||||
-rw-r--r-- | lib/private/helper.php | 121 | ||||
-rw-r--r-- | lib/private/preview.php | 2 | ||||
-rw-r--r-- | lib/private/server.php | 82 | ||||
-rw-r--r-- | lib/private/templatelayout.php | 5 | ||||
-rw-r--r-- | lib/private/tempmanager.php | 146 | ||||
-rw-r--r-- | lib/private/util.php | 4 |
12 files changed, 229 insertions, 172 deletions
diff --git a/lib/private/db.php b/lib/private/db.php index 9b904a1518f..b820281b8a3 100644 --- a/lib/private/db.php +++ b/lib/private/db.php @@ -205,6 +205,13 @@ class OC_DB { } /** + * Rollback the database changes done during a transaction that is in progress + */ + public static function rollback() { + return \OC::$server->getDatabaseConnection()->rollback(); + } + + /** * saves database schema to xml file * @param string $file name of file * @param int $mode diff --git a/lib/private/db/connectionfactory.php b/lib/private/db/connectionfactory.php index 1f676f1fca2..f6253e09b95 100644 --- a/lib/private/db/connectionfactory.php +++ b/lib/private/db/connectionfactory.php @@ -153,6 +153,13 @@ class ConnectionFactory { } $connectionParams['tablePrefix'] = $config->getSystemValue('dbtableprefix', 'oc_'); + + //additional driver options, eg. for mysql ssl + $driverOptions = $config->getSystemValue('dbdriveroptions', null); + if ($driverOptions) { + $connectionParams['driverOptions'] = $driverOptions; + } + return $connectionParams; } } diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index 3c367f144db..632e320576c 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -144,7 +144,7 @@ class MDB2SchemaManager { } /** - * @param \Doctrine\DBAL\Schema\Schema $schema + * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema * @return bool */ private function executeSchemaChange($schema) { diff --git a/lib/private/files.php b/lib/private/files.php index a983f6f32f5..571d3215caa 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -195,7 +195,7 @@ class OC_Files { * @param ZipStreamer $zip * @param string $internalDir */ - public static function zipAddDir($dir, $zip, $internalDir='') { + public static function zipAddDir($dir, ZipStreamer $zip, $internalDir='') { $dirname=basename($dir); $rootDir = $internalDir.$dirname; if (!empty($rootDir)) { diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php index e5180cfe173..0ccf42941de 100644 --- a/lib/private/files/mount/manager.php +++ b/lib/private/files/mount/manager.php @@ -19,7 +19,7 @@ class Manager { /** * @param Mount $mount */ - public function addMount($mount) { + public function addMount(Mount $mount) { $this->mounts[$mount->getMountPoint()] = $mount; } diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php index 0a612ae505b..1c5fafc12fa 100644 --- a/lib/private/files/storage/local.php +++ b/lib/private/files/storage/local.php @@ -90,6 +90,7 @@ if (\OC_Util::runningOnWindows()) { } public function stat($path) { + clearstatcache(); $fullPath = $this->datadir . $path; $statResult = stat($fullPath); if (PHP_INT_SIZE === 4 && !$this->is_dir($path)) { @@ -276,5 +277,25 @@ if (\OC_Util::runningOnWindows()) { public function isLocal() { return true; } + + /** + * get the ETag for a file or folder + * + * @param string $path + * @return string + */ + public function getETag($path) { + if ($this->is_file($path)) { + $stat = $this->stat($path); + return md5( + $stat['mtime'] . + $stat['ino'] . + $stat['dev'] . + $stat['size'] + ); + } else { + return parent::getETag($path); + } + } } } diff --git a/lib/private/helper.php b/lib/private/helper.php index 628af14fa08..5b1d31bfc59 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -25,7 +25,6 @@ * Collection of useful functions */ class OC_Helper { - private static $tmpFiles = array(); private static $mimetypeIcons = array(); private static $mimetypeDetector; private static $templateManager; @@ -593,136 +592,24 @@ class OC_Helper { * * @param string $postfix * @return string + * @deprecated Use the TempManager instead * * temporary files are automatically cleaned up after the script is finished */ public static function tmpFile($postfix = '') { - $file = get_temp_dir() . '/' . md5(time() . rand()) . $postfix; - $fh = fopen($file, 'w'); - if ($fh!==false){ - fclose($fh); - self::$tmpFiles[] = $file; - } else { - OC_Log::write( - 'OC_Helper', - sprintf( - 'Can not create a temporary file in directory %s. Check it exists and has correct permissions', - get_temp_dir() - ), - OC_Log::WARN - ); - $file = false; - } - return $file; - } - - /** - * move a file to oc-noclean temp dir - * - * @param string $filename - * @return mixed - * - */ - public static function moveToNoClean($filename = '') { - if ($filename == '') { - return false; - } - $tmpDirNoClean = get_temp_dir() . '/oc-noclean/'; - if (!file_exists($tmpDirNoClean) || !is_dir($tmpDirNoClean)) { - if (file_exists($tmpDirNoClean)) { - unlink($tmpDirNoClean); - } - mkdir($tmpDirNoClean); - } - $newname = $tmpDirNoClean . basename($filename); - if (rename($filename, $newname)) { - return $newname; - } else { - return false; - } + return \OC::$server->getTempManager()->getTemporaryFile($postfix); } /** * create a temporary folder with an unique filename * * @return string + * @deprecated Use the TempManager instead * * temporary files are automatically cleaned up after the script is finished */ public static function tmpFolder() { - $path = get_temp_dir() . DIRECTORY_SEPARATOR . md5(time() . rand()); - mkdir($path); - self::$tmpFiles[] = $path; - return $path . DIRECTORY_SEPARATOR; - } - - /** - * remove all files created by self::tmpFile - */ - public static function cleanTmp() { - $leftoversFile = get_temp_dir() . '/oc-not-deleted'; - if (file_exists($leftoversFile)) { - $leftovers = file($leftoversFile); - foreach ($leftovers as $file) { - try { - self::rmdirr($file); - } catch (UnexpectedValueException $ex) { - // not really much we can do here anymore - if (!is_null(\OC::$server)) { - $message = $ex->getMessage(); - \OC::$server->getLogger()->error("Error deleting file/folder: $file - Reason: $message", - array('app' => 'core')); - } - } - } - unlink($leftoversFile); - } - - foreach (self::$tmpFiles as $file) { - if (file_exists($file)) { - try { - if (!self::rmdirr($file)) { - file_put_contents($leftoversFile, $file . "\n", FILE_APPEND); - } - } catch (UnexpectedValueException $ex) { - // not really much we can do here anymore - if (!is_null(\OC::$server)) { - $message = $ex->getMessage(); - \OC::$server->getLogger()->error("Error deleting file/folder: $file - Reason: $message", - array('app' => 'core')); - } - } - } - } - } - - /** - * remove all files in PHP /oc-noclean temp dir - */ - public static function cleanTmpNoClean() { - $tmpDirNoCleanName=get_temp_dir() . '/oc-noclean/'; - if(file_exists($tmpDirNoCleanName) && is_dir($tmpDirNoCleanName)) { - $files=scandir($tmpDirNoCleanName); - foreach($files as $file) { - $fileName = $tmpDirNoCleanName . $file; - if (!\OC\Files\Filesystem::isIgnoredDir($file) && filemtime($fileName) + 600 < time()) { - unlink($fileName); - } - } - // if oc-noclean is empty delete it - $isTmpDirNoCleanEmpty = true; - $tmpDirNoClean = opendir($tmpDirNoCleanName); - if(is_resource($tmpDirNoClean)) { - while (false !== ($file = readdir($tmpDirNoClean))) { - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { - $isTmpDirNoCleanEmpty = false; - } - } - } - if ($isTmpDirNoCleanEmpty) { - rmdir($tmpDirNoCleanName); - } - } + return \OC::$server->getTempManager()->getTemporaryFolder(); } /** diff --git a/lib/private/preview.php b/lib/private/preview.php index f8b19f11cb0..dbbe173bf80 100644 --- a/lib/private/preview.php +++ b/lib/private/preview.php @@ -779,7 +779,7 @@ class Preview { * @param \OC\Files\FileInfo $file * @return bool */ - public static function isAvailable($file) { + public static function isAvailable(\OC\Files\FileInfo $file) { if (!\OC_Config::getValue('enable_previews', true)) { return false; } diff --git a/lib/private/server.php b/lib/private/server.php index b0d63af1554..186714740f7 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -72,15 +72,15 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('PreviewManager', function ($c) { return new PreviewManager(); }); - $this->registerService('TagMapper', function($c) { + $this->registerService('TagMapper', function(Server $c) { return new TagMapper($c->getDb()); }); - $this->registerService('TagManager', function ($c) { + $this->registerService('TagManager', function (Server $c) { $tagMapper = $c->query('TagMapper'); $user = \OC_User::getUser(); return new TagManager($tagMapper, $user); }); - $this->registerService('RootFolder', function ($c) { + $this->registerService('RootFolder', function (Server $c) { // TODO: get user and user manager from container as well $user = \OC_User::getUser(); /** @var $c SimpleContainer */ @@ -90,28 +90,16 @@ class Server extends SimpleContainer implements IServerContainer { $view = new View(); return new Root($manager, $view, $user); }); - $this->registerService('UserManager', function ($c) { - /** - * @var SimpleContainer $c - * @var \OC\AllConfig $config - */ - $config = $c->query('AllConfig'); + $this->registerService('UserManager', function (Server $c) { + $config = $c->getConfig(); return new \OC\User\Manager($config); }); - $this->registerService('GroupManager', function ($c) { - /** - * @var SimpleContainer $c - * @var \OC\User\Manager $userManager - */ - $userManager = $c->query('UserManager'); + $this->registerService('GroupManager', function (Server $c) { + $userManager = $c->getUserManager(); return new \OC\Group\Manager($userManager); }); - $this->registerService('UserSession', function ($c) { - /** - * @var SimpleContainer $c - * @var \OC\User\Manager $manager - */ - $manager = $c->query('UserManager'); + $this->registerService('UserSession', function (Server $c) { + $manager = $c->getUserManager(); $userSession = new \OC\User\Session($manager, new \OC\Session\Memory('')); $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); @@ -160,9 +148,8 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('L10NFactory', function ($c) { return new \OC\L10N\Factory(); }); - $this->registerService('URLGenerator', function ($c) { - /** @var $c SimpleContainer */ - $config = $c->query('AllConfig'); + $this->registerService('URLGenerator', function (Server $c) { + $config = $c->getConfig(); return new \OC\URLGenerator($config); }); $this->registerService('AppHelper', function ($c) { @@ -181,25 +168,18 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('AvatarManager', function ($c) { return new AvatarManager(); }); - $this->registerService('Logger', function ($c) { - /** @var $c SimpleContainer */ + $this->registerService('Logger', function (Server $c) { $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); $logger = 'OC_Log_' . ucfirst($logClass); call_user_func(array($logger, 'init')); return new Log($logger); }); - $this->registerService('JobList', function ($c) { - /** - * @var Server $c - */ + $this->registerService('JobList', function (Server $c) { $config = $c->getConfig(); return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config); }); - $this->registerService('Router', function ($c) { - /** - * @var Server $c - */ + $this->registerService('Router', function (Server $c) { $cacheFactory = $c->getMemCacheFactory(); if ($cacheFactory->isAvailable()) { $router = new \OC\Route\CachingRouter($cacheFactory->create('route')); @@ -214,13 +194,10 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('SecureRandom', function ($c) { return new SecureRandom(); }); - $this->registerService('Crypto', function ($c) { - return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom()); + $this->registerService('Crypto', function (Server $c) { + return new Crypto($c->getConfig(), $c->getSecureRandom()); }); - $this->registerService('DatabaseConnection', function ($c) { - /** - * @var Server $c - */ + $this->registerService('DatabaseConnection', function (Server $c) { $factory = new \OC\DB\ConnectionFactory(); $type = $c->getConfig()->getSystemValue('dbtype', 'sqlite'); if (!$factory->isValidType($type)) { @@ -231,18 +208,14 @@ class Server extends SimpleContainer implements IServerContainer { $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); return $connection; }); - $this->registerService('Db', function ($c) { - /** - * @var Server $c - */ + $this->registerService('Db', function (Server $c) { return new Db($c->getDatabaseConnection()); }); - $this->registerService('HTTPHelper', function (SimpleContainer $c) { - $config = $c->query('AllConfig'); + $this->registerService('HTTPHelper', function (Server $c) { + $config = $c->getConfig(); return new HTTPHelper($config); }); - $this->registerService('EventLogger', function ($c) { - /** @var Server $c */ + $this->registerService('EventLogger', function (Server $c) { if (defined('DEBUG') and DEBUG) { return new EventLogger(); } else { @@ -256,6 +229,10 @@ class Server extends SimpleContainer implements IServerContainer { return new NullQueryLogger(); } }); + $this->registerService('TempManager', function ($c) { + /** @var Server $c */ + return new TempManager(get_temp_dir(), $c->getLogger()); + }); } /** @@ -617,4 +594,13 @@ class Server extends SimpleContainer implements IServerContainer { function getQueryLogger() { return $this->query('QueryLogger'); } + + /** + * Get the manager for temporary files and folders + * + * @return \OCP\ITempManager + */ + function getTempManager() { + return $this->query('TempManager'); + } } diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php index cbaadd5768f..a93449f202f 100644 --- a/lib/private/templatelayout.php +++ b/lib/private/templatelayout.php @@ -33,7 +33,6 @@ class OC_TemplateLayout extends OC_Template { $this->config = \OC::$server->getConfig(); // Decide which page we show - if( $renderAs == 'user' ) { parent::__construct( 'core', 'layout.user' ); if(in_array(OC_APP::getCurrentApp(), array('settings','admin', 'help'))!==false) { @@ -85,7 +84,11 @@ class OC_TemplateLayout extends OC_Template { $this->assign('bodyid', 'body-login'); } else { parent::__construct('core', 'layout.base'); + } + // Send the language to our layouts + $this->assign('language', OC_L10N::findLanguage()); + if(empty(self::$versionHash)) { self::$versionHash = md5(implode(',', OC_App::getAppVersions())); diff --git a/lib/private/tempmanager.php b/lib/private/tempmanager.php new file mode 100644 index 00000000000..a3bb07f9d63 --- /dev/null +++ b/lib/private/tempmanager.php @@ -0,0 +1,146 @@ +<?php + +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC; + +use OCP\ILogger; +use OCP\ITempManager; + +class TempManager implements ITempManager { + /** + * Current temporary files and folders + * + * @var string[] + */ + protected $current = array(); + + /** + * i.e. /tmp on linux systems + * + * @var string + */ + protected $tmpBaseDir; + + /** + * @var \OCP\ILogger + */ + protected $log; + + /** + * @param string $baseDir + * @param \OCP\ILogger $logger + */ + public function __construct($baseDir, ILogger $logger) { + $this->tmpBaseDir = $baseDir; + $this->log = $logger; + } + + protected function generatePath($postFix) { + return $this->tmpBaseDir . '/oc_tmp_' . md5(time() . rand()) . $postFix; + } + + /** + * Create a temporary file and return the path + * + * @param string $postFix + * @return string + */ + public function getTemporaryFile($postFix = '') { + $file = $this->generatePath($postFix); + if (is_writable($this->tmpBaseDir)) { + touch($file); + $this->current[] = $file; + return $file; + } else { + $this->log->warning( + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', + array( + 'dir' => $this->tmpBaseDir + ) + ); + return false; + } + } + + /** + * Create a temporary folder and return the path + * + * @param string $postFix + * @return string + */ + public function getTemporaryFolder($postFix = '') { + $path = $this->generatePath($postFix); + if (is_writable($this->tmpBaseDir)) { + mkdir($path); + $this->current[] = $path; + return $path . '/'; + } else { + $this->log->warning( + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', + array( + 'dir' => $this->tmpBaseDir + ) + ); + return false; + } + } + + /** + * Remove the temporary files and folders generated during this request + */ + public function clean() { + $this->cleanFiles($this->current); + } + + protected function cleanFiles($files) { + foreach ($files as $file) { + if (file_exists($file)) { + try { + \OC_Helper::rmdirr($file); + } catch (\UnexpectedValueException $ex) { + $this->log->warning( + "Error deleting temporary file/folder: {file} - Reason: {error}", + array( + 'file' => $file, + 'error' => $ex->getMessage() + ) + ); + } + } + } + } + + /** + * Remove old temporary files and folders that were failed to be cleaned + */ + public function cleanOld() { + $this->cleanFiles($this->getOldFiles()); + } + + /** + * Get all temporary files and folders generated by oc older than an hour + * + * @return string[] + */ + protected function getOldFiles() { + $cutOfTime = time() - 3600; + $files = array(); + $dh = opendir($this->tmpBaseDir); + while (($file = readdir($dh)) !== false) { + if (substr($file, 0, 7) === 'oc_tmp_') { + $path = $this->tmpBaseDir . '/' . $file; + $mtime = filemtime($path); + if ($mtime < $cutOfTime) { + $files[] = $path; + } + } + } + return $files; + } +} diff --git a/lib/private/util.php b/lib/private/util.php index dd131e41310..6cd982c222e 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -420,7 +420,7 @@ class OC_Util { * @param \OCP\IConfig $config * @return array arrays with error messages and hints */ - public static function checkServer($config) { + public static function checkServer(\OCP\IConfig $config) { $l = \OC::$server->getL10N('lib'); $errors = array(); $CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data'); @@ -1306,7 +1306,7 @@ class OC_Util { * @param \OCP\IConfig $config * @return bool whether the core or any app needs an upgrade */ - public static function needUpgrade($config) { + public static function needUpgrade(\OCP\IConfig $config) { if ($config->getSystemValue('installed', false)) { $installedVersion = $config->getSystemValue('version', '0.0.0'); $currentVersion = implode('.', OC_Util::getVersion()); |