From 0cbd861fedaec3a148a9f2f494de7553ac71958e Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Mon, 21 Sep 2009 09:56:05 +0000 Subject: [PATCH] SimpleSAML_Utilities: Add getTempDir()-function. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1761 44740490-163a-0410-bde0-09ae8108e29a --- config-templates/config.php | 9 ++++++++- lib/SimpleSAML/Utilities.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/config-templates/config.php b/config-templates/config.php index 89605903b..1da08d2a1 100644 --- a/config-templates/config.php +++ b/config-templates/config.php @@ -28,7 +28,14 @@ $config = array ( 'certdir' => 'cert/', 'dictionarydir' => 'dictionaries/', 'loggingdir' => 'log/', - + + /* + * A directory where simpleSAMLphp can save temporary files. + * + * SimpleSAMLphp will attempt to create this directory if it doesn't exist. + */ + 'tempdir' => '/tmp/simplesaml', + 'version' => 'trunk', /** diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 95a9db9a1..b1d37a739 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -2027,6 +2027,36 @@ class SimpleSAML_Utilities { } } + + /** + * Get temp directory path. + * + * This function retrieves the path to a directory where + * temporary files can be saved. + * + * @return string Path to temp directory, without a trailing '/'. + */ + public static function getTempDir() { + + $globalConfig = SimpleSAML_Configuration::getInstance(); + + $tempDir = $globalConfig->getString('tempdir', '/tmp/simplesaml'); + + while (substr($tempDir, -1) === '/') { + $tempDir = substr($tempDir, 0, -1); + } + + if (!is_dir($tempDir)) { + $ret = mkdir($tempDir, 0700, TRUE); + if (!$ret) { + throw new SimpleSAML_Error_Exception('Error creating temp dir ' . + var_export($tempDir, TRUE) . ': ' . SimpleSAML_Utilities::getLastError()); + } + } + + return $tempDir; + } + } ?> \ No newline at end of file -- GitLab