Skip to content

Commit 8135e71

Browse files
committed
Improve performance of permission checking
1 parent 17695c8 commit 8135e71

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Models/UpdateExecutor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function setBasePath(string $path): self
5252
*/
5353
public function run(Release $release): bool
5454
{
55-
if (checkPermissions((new Finder())->in($this->basePath))) {
55+
if (checkPermissions($this->basePath)) {
5656
$releaseFolder = createFolderFromFile($release->getStoragePath());
5757

5858
// Move all directories first

src/helpers.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,22 @@ function dirsIntersect(array $directory, array $excludedDirs): bool
2828
*
2929
* @return bool
3030
*/
31-
function checkPermissions(Finder $directory): bool
31+
function checkPermissions(string $directory): bool
3232
{
33-
$checkPermission = true;
3433

35-
collect($directory->getIterator())->each(function (SplFileInfo $file) use (&$checkPermission) {
36-
if ($file->isWritable() === false) {
37-
$checkPermission = false;
34+
$directoryIterator = new \RecursiveDirectoryIterator($directory);
35+
36+
foreach(new \RecursiveIteratorIterator($directoryIterator) as $file) {
37+
38+
if(is_file($file) && !is_writable($file)) {
39+
40+
return false;
41+
3842
}
39-
});
4043

41-
return $checkPermission;
44+
}
45+
46+
return true;
4247
}
4348
}
4449

0 commit comments

Comments
 (0)