Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit d843e33

Browse files
committed
Merge pull request #256 from gkralik/fix/firefox-profile-cleanup-temp
FirefoxProfile: clean up temporary files
2 parents 96bacb4 + cb04dc7 commit d843e33

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/Firefox/FirefoxProfile.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function encode() {
9999
$zip->close();
100100

101101
$profile = base64_encode(file_get_contents($temp_zip));
102+
103+
// clean up
104+
$this->deleteDirectory($temp_dir);
105+
unlink($temp_zip);
106+
102107
return $profile;
103108
}
104109

@@ -123,6 +128,10 @@ private function installExtension($extension, $profile_dir) {
123128
mkdir($ext_dir, 0777, true);
124129

125130
$this->extractTo($extension, $ext_dir);
131+
132+
// clean up
133+
$this->deleteDirectory($temp_dir);
134+
126135
return $ext_dir;
127136
}
128137

@@ -144,6 +153,24 @@ private function createTempDirectory($prefix = '') {
144153
return $temp_dir;
145154
}
146155

156+
/**
157+
* @param string $directory The path to the directory.
158+
*/
159+
private function deleteDirectory($directory) {
160+
$dir = new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS);
161+
$paths = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
162+
163+
foreach ($paths as $path) {
164+
if ($path->isDir() && !$path->isLink()) {
165+
rmdir($path->getPathname());
166+
} else {
167+
unlink($path->getPathname());
168+
}
169+
}
170+
171+
rmdir($directory);
172+
}
173+
147174
/**
148175
* @param string $xpi The path to the .xpi extension.
149176
* @param string $target_dir The path to the unzip directory.

0 commit comments

Comments
 (0)