Skip to content

Commit d2b24df

Browse files
committed
fix(renamer-page): suppress cleanup exceptions to avoid masking primary failure
Wrap recursive directory removal in try-catch with @ error suppression so that cleanup failures do not mask the primary exception when remove_path() is called from a catch block.
1 parent 143aac0 commit d2b24df

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

src/Plugin/Admin/RenamerPage.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,24 @@ private function remove_path( string $path ): void {
419419
return;
420420
}
421421

422-
$iterator = new \RecursiveIteratorIterator(
423-
new \RecursiveDirectoryIterator( $path, \FilesystemIterator::SKIP_DOTS ),
424-
\RecursiveIteratorIterator::CHILD_FIRST
425-
);
422+
try {
423+
$iterator = new \RecursiveIteratorIterator(
424+
new \RecursiveDirectoryIterator( $path, \FilesystemIterator::SKIP_DOTS ),
425+
\RecursiveIteratorIterator::CHILD_FIRST
426+
);
426427

427-
foreach ( $iterator as $item ) {
428-
if ( $item->isDir() && ! $item->isLink() ) {
429-
rmdir( $item->getPathname() ); // phpcs:ignore WordPress.WP.AlternativeFunctions
430-
continue;
428+
foreach ( $iterator as $item ) {
429+
if ( $item->isDir() && ! $item->isLink() ) {
430+
@rmdir( $item->getPathname() ); // phpcs:ignore WordPress.WP.AlternativeFunctions
431+
continue;
432+
}
433+
434+
@unlink( $item->getPathname() ); // phpcs:ignore WordPress.WP.AlternativeFunctions
431435
}
432436

433-
unlink( $item->getPathname() ); // phpcs:ignore WordPress.WP.AlternativeFunctions
437+
@rmdir( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions
438+
} catch ( \Throwable $e ) {
439+
// Fail silently to avoid masking the primary exception during cleanup.
434440
}
435-
436-
rmdir( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions
437441
}
438442
}

0 commit comments

Comments
 (0)