summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorroot <martin.mattel@diemattels.at>2015-05-29 21:56:08 +0200
committerRobin McCorkell <rmccorkell@owncloud.com>2015-08-29 16:59:02 +0100
commitacae208f2fc6b80fbf9af615661e3905f9cab0a0 (patch)
tree61ac4b858698626ea4fa9c7e541da9563c3991ad /lib
parent723f8c8f1ba8c9859ec2d46515dc06e7236f89c0 (diff)
downloadnextcloud-server-acae208f2fc6b80fbf9af615661e3905f9cab0a0.tar.gz
nextcloud-server-acae208f2fc6b80fbf9af615661e3905f9cab0a0.zip
moved code to /lib/private/tempmanager.php
fix for unit test some fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php17
-rw-r--r--lib/private/server.php2
-rw-r--r--lib/private/tempmanager.php60
3 files changed, 61 insertions, 18 deletions
diff --git a/lib/base.php b/lib/base.php
index aceac2e53c3..f1f8a0f92ca 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -1108,27 +1108,16 @@ class OC {
}
return true;
}
-}
-if (!function_exists('get_temp_dir')) {
/**
* Get the temporary dir to store uploaded data
* @return null|string Path to the temporary directory or null
*/
function get_temp_dir() {
- if ($temp = ini_get('upload_tmp_dir')) return $temp;
- if ($temp = getenv('TMP')) return $temp;
- if ($temp = getenv('TEMP')) return $temp;
- if ($temp = getenv('TMPDIR')) return $temp;
- $temp = tempnam(__FILE__, '');
- if (file_exists($temp)) {
- unlink($temp);
- return dirname($temp);
- }
- if ($temp = sys_get_temp_dir()) return $temp;
-
- return null;
+ return \OC::$server->getTempManager()->t_get_temp_dir();
}
+
}
+
OC::init();
diff --git a/lib/private/server.php b/lib/private/server.php
index a47fa2e43f9..229fae843cc 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -344,7 +344,7 @@ class Server extends SimpleContainer implements IServerContainer {
}
});
$this->registerService('TempManager', function (Server $c) {
- return new TempManager(get_temp_dir(), $c->getLogger());
+ return new TempManager($c->getLogger());
});
$this->registerService('AppManager', function(Server $c) {
return new \OC\App\AppManager(
diff --git a/lib/private/tempmanager.php b/lib/private/tempmanager.php
index b8cef8e036e..b1b98751607 100644
--- a/lib/private/tempmanager.php
+++ b/lib/private/tempmanager.php
@@ -38,11 +38,10 @@ class TempManager implements ITempManager {
const TMP_PREFIX = 'oc_tmp_';
/**
- * @param string $baseDir
* @param \OCP\ILogger $logger
*/
- public function __construct($baseDir, ILogger $logger) {
- $this->tmpBaseDir = $baseDir;
+ public function __construct(ILogger $logger) {
+ $this->tmpBaseDir = $this->t_get_temp_dir();
$this->log = $logger;
}
@@ -190,4 +189,59 @@ class TempManager implements ITempManager {
}
return $files;
}
+
+ /**
+ * Get the temporary directory to store transfer data
+ * @return null|string Path to the temporary directory or null
+ */
+ public function t_get_temp_dir() {
+ // Get the temporary directory and log the path if loglevel is set to debug
+ // Info: based on the temp dir, further directories may be created unique to the instance
+ $temp = self::gather_temp_dir();
+ \OCP\Util::writeLog('Core', 'Temporary directory set to: ' . ($temp ? $temp : 'NULL'), \OCP\Util::DEBUG);
+ return $temp;
+ }
+
+ /**
+ * Get a temporary directory from possible sources
+ * If a temporary directory is set in config.php, use this one
+ * @return null|string Path to the temporary directory or null
+ */
+ private function gather_temp_dir() {
+ if ($temp = self::get_config_temp_dir()) return $temp;
+ if ($temp = ini_get('upload_tmp_dir')) return $temp;
+ if ($temp = getenv('TMP')) return $temp;
+ if ($temp = getenv('TEMP')) return $temp;
+ if ($temp = getenv('TMPDIR')) return $temp;
+ $temp = tempnam(__FILE__, '');
+ if (file_exists($temp)) {
+ unlink($temp);
+ return dirname($temp);
+ }
+ if ($temp = sys_get_temp_dir()) return $temp;
+ return null;
+ }
+
+ /**
+ * Check if the temporary directory is defined in config.php and is present and writable
+ * @return bool|string Path to the temporary directory or false
+ */
+ private function get_config_temp_dir() {
+ $temp = \OC::$server->getConfig()->getSystemValue('tempdirectory', false);
+ // surpress any possible errors caused by is_writable
+ // checks missing or invalid path or characters, wrong permissions ect
+ if ($temp) {
+ try {
+ if (is_writeable($temp)) {
+ return $temp;
+ } else {
+ \OCP\Util::writeLog('Core', 'Manually set temporary directory in config.php is not present or writable: ' . $temp, \OCP\Util::WARN);
+ return false;
+ }
+ } catch (Exception $e) {
+ return false;
+ }
+ }
+ }
+
}