Skip to content

Commit 071fc73

Browse files
Copilotswissspidy
andcommitted
Check unlink() return value in process_prune, log warning on failure
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 9102a6f commit 071fc73

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/Media_Command.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ private function process_prune( $id, $image_sizes, $remove_abandoned, $progress,
10351035
$registered_sizes = get_intermediate_image_sizes();
10361036
$dir_path = dirname( $fullsizepath ) . '/';
10371037
$sizes_to_prune = array();
1038+
$failed_delete = false;
10381039

10391040
foreach ( $metadata['sizes'] as $size_name => $size_meta ) {
10401041
// The 'full' size is not an intermediate size and should never be pruned.
@@ -1064,16 +1065,22 @@ private function process_prune( $id, $image_sizes, $remove_abandoned, $progress,
10641065
continue;
10651066
}
10661067

1067-
if ( file_exists( $intermediate_path ) ) {
1068-
unlink( $intermediate_path );
1068+
if ( file_exists( $intermediate_path ) && ! unlink( $intermediate_path ) ) {
1069+
WP_CLI::warning( "Could not delete thumbnail file '{$size_meta['file']}' for $att_desc." );
1070+
$failed_delete = true;
1071+
continue;
10691072
}
10701073

10711074
$sizes_to_prune[] = $size_name;
10721075
}
10731076

10741077
if ( empty( $sizes_to_prune ) ) {
1075-
WP_CLI::log( "$progress No thumbnails to prune for $att_desc." );
1076-
++$skips;
1078+
if ( $failed_delete ) {
1079+
++$errors;
1080+
} else {
1081+
WP_CLI::log( "$progress No thumbnails to prune for $att_desc." );
1082+
++$skips;
1083+
}
10771084
return;
10781085
}
10791086

0 commit comments

Comments
 (0)