Skip to content

Commit 0cbd861

Browse files
committed
SimpleSAML_Utilities: Add getTempDir()-function.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1761 44740490-163a-0410-bde0-09ae8108e29a
1 parent 250bbd4 commit 0cbd861

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

config-templates/config.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
'certdir' => 'cert/',
2929
'dictionarydir' => 'dictionaries/',
3030
'loggingdir' => 'log/',
31-
31+
32+
/*
33+
* A directory where simpleSAMLphp can save temporary files.
34+
*
35+
* SimpleSAMLphp will attempt to create this directory if it doesn't exist.
36+
*/
37+
'tempdir' => '/tmp/simplesaml',
38+
3239
'version' => 'trunk',
3340

3441
/**

lib/SimpleSAML/Utilities.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,36 @@ public static function writeFile($filename, $data) {
20272027
}
20282028
}
20292029

2030+
2031+
/**
2032+
* Get temp directory path.
2033+
*
2034+
* This function retrieves the path to a directory where
2035+
* temporary files can be saved.
2036+
*
2037+
* @return string Path to temp directory, without a trailing '/'.
2038+
*/
2039+
public static function getTempDir() {
2040+
2041+
$globalConfig = SimpleSAML_Configuration::getInstance();
2042+
2043+
$tempDir = $globalConfig->getString('tempdir', '/tmp/simplesaml');
2044+
2045+
while (substr($tempDir, -1) === '/') {
2046+
$tempDir = substr($tempDir, 0, -1);
2047+
}
2048+
2049+
if (!is_dir($tempDir)) {
2050+
$ret = mkdir($tempDir, 0700, TRUE);
2051+
if (!$ret) {
2052+
throw new SimpleSAML_Error_Exception('Error creating temp dir ' .
2053+
var_export($tempDir, TRUE) . ': ' . SimpleSAML_Utilities::getLastError());
2054+
}
2055+
}
2056+
2057+
return $tempDir;
2058+
}
2059+
20302060
}
20312061

20322062
?>

0 commit comments

Comments
 (0)