Page MenuHomePhabricator

D10329.id24869.diff
No OneTemporary

D10329.id24869.diff

diff --git a/src/filesystem/TempFile.php b/src/filesystem/TempFile.php
--- a/src/filesystem/TempFile.php
+++ b/src/filesystem/TempFile.php
@@ -19,6 +19,7 @@
private $dir;
private $file;
private $preserve;
+ private $destroyed = false;
/* -( Creating a Temporary File )------------------------------------------ */
@@ -39,6 +40,10 @@
$this->file = $this->dir.'/'.$filename;
}
+ // If we fatal (e.g., call a method on NULL), destructors are not called.
+ // Make sure our destructor is invoked.
+ register_shutdown_function(array($this, '__destruct'));
+
Filesystem::writeFile($this, '');
}
@@ -82,9 +87,14 @@
* @task internal
*/
public function __destruct() {
+ if ($this->destroyed) {
+ return;
+ }
+
if ($this->preserve) {
return;
}
+
Filesystem::remove($this->dir);
// NOTE: tempnam() doesn't guarantee it will return a file inside the
@@ -92,6 +102,10 @@
// explicitly.
Filesystem::remove($this->file);
+
+ $this->file = null;
+ $this->dir = null;
+ $this->destroyed = true;
}
}

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 5, 10:52 AM (3 d, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7225204
Default Alt Text
D10329.id24869.diff (1 KB)

Event Timeline