Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14041902
D19521.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D19521.diff
View Options
diff --git a/src/filesystem/Filesystem.php b/src/filesystem/Filesystem.php
--- a/src/filesystem/Filesystem.php
+++ b/src/filesystem/Filesystem.php
@@ -677,18 +677,30 @@
* @param string Optional directory prefix.
* @param int Permissions to create the directory with. By default,
* these permissions are very restrictive (0700).
+ * @param string Optional root directory. If not provided, the system
+ * temporary directory (often "/tmp") will be used.
* @return string Path to newly created temporary directory.
*
* @task directory
*/
- public static function createTemporaryDirectory($prefix = '', $umask = 0700) {
+ public static function createTemporaryDirectory(
+ $prefix = '',
+ $umask = 0700,
+ $root_directory = null) {
$prefix = preg_replace('/[^A-Z0-9._-]+/i', '', $prefix);
- $tmp = sys_get_temp_dir();
- if (!$tmp) {
- throw new FilesystemException(
- $tmp,
- pht('Unable to determine system temporary directory.'));
+ if ($root_directory !== null) {
+ $tmp = $root_directory;
+ self::assertExists($tmp);
+ self::assertIsDirectory($tmp);
+ self::assertWritable($tmp);
+ } else {
+ $tmp = sys_get_temp_dir();
+ if (!$tmp) {
+ throw new FilesystemException(
+ $tmp,
+ pht('Unable to determine system temporary directory.'));
+ }
}
$base = $tmp.DIRECTORY_SEPARATOR.$prefix;
diff --git a/src/filesystem/TempFile.php b/src/filesystem/TempFile.php
--- a/src/filesystem/TempFile.php
+++ b/src/filesystem/TempFile.php
@@ -30,10 +30,15 @@
* @param string? Filename hint. This is useful if you intend to edit the
* file with an interactive editor, so the user's editor shows
* "commit-message" instead of "p3810hf-1z9b89bas".
+ * @param string? Root directory to hold the file. If omitted, the system
+ * temporary directory (often "/tmp") will be used by default.
* @task create
*/
- public function __construct($filename = null) {
- $this->dir = Filesystem::createTemporaryDirectory();
+ public function __construct($filename = null, $root_directory = null) {
+ $this->dir = Filesystem::createTemporaryDirectory(
+ '',
+ 0700,
+ $root_directory);
if ($filename === null) {
$this->file = tempnam($this->dir, getmypid().'-');
} else {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 12, 10:34 PM (5 d, 14 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6746813
Default Alt Text
D19521.diff (2 KB)
Attached To
Mode
D19521: Allow callers to choose which directory a "TempFile" is created in
Attached
Detach File
Event Timeline
Log In to Comment