Skip to content

Commit 731843c

Browse files
authored
Merge pull request #957 from cloudinary/fix/fragments-handling
Fix closing the filestream and deleting the fragment
2 parents 1783bd7 + 0851d9b commit 731843c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

php/class-utils.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,10 @@ public static function download_fragment( $url, $size = 1048576 ) {
670670
if ( empty( $index ) ) {
671671
add_action( 'shutdown', array( __CLASS__, 'purge_fragments' ) );
672672
}
673-
self::$file_fragments[ $index ] = $temp_file;
673+
self::$file_fragments[ $index ] = array(
674+
'pointer' => $pointer,
675+
'file' => $temp_file,
676+
);
674677
// Get the metadata of the stream.
675678
$data = stream_get_meta_data( $pointer );
676679
// Stream the content to the temp file.
@@ -710,8 +713,8 @@ public static function purge_fragments() {
710713
*/
711714
public static function purge_fragment( $index ) {
712715
if ( isset( self::$file_fragments[ $index ] ) ) {
713-
fclose( self::$file_fragments[ $index ] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
714-
unset( self::$file_fragments[ $index ] );
716+
fclose( self::$file_fragments[ $index ]['pointer'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
717+
unlink( self::$file_fragments[ $index ]['file'] );
715718
}
716719
}
717720

0 commit comments

Comments
 (0)