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

Commit da5cbd3

Browse files
committed
recursively delete temporary directories
rmdir() will only succeed if the target directory is empty. use a helper function to recursively delete the target directory contents before using rmdir() on it.
1 parent 6bb9fdf commit da5cbd3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/Firefox/FirefoxProfile.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public function encode() {
100100
$profile = base64_encode(file_get_contents($temp_zip));
101101

102102
// clean up
103-
rmdir($temp_dir);
103+
$this->deleteDirectory($temp_dir);
104104
unlink($temp_zip);
105-
105+
106106
return $profile;
107107
}
108108

@@ -129,8 +129,8 @@ private function installExtension($extension, $profile_dir) {
129129
$this->extractTo($extension, $ext_dir);
130130

131131
// clean up
132-
rmdir($temp_dir);
133-
132+
$this->deleteDirectory($temp_dir);
133+
134134
return $ext_dir;
135135
}
136136

@@ -152,6 +152,23 @@ private function createTempDirectory($prefix = '') {
152152
return $temp_dir;
153153
}
154154

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

0 commit comments

Comments
 (0)