Index: wp-inst/wp-includes/functions-post.php
===================================================================
--- wp-inst/wp-includes/functions-post.php	(revision 1518)
+++ wp-inst/wp-includes/functions-post.php	(working copy)
@@ -384,10 +384,15 @@
 
 	if ( ! empty($meta['thumb']) ) {
 		// Don't delete the thumb if another attachment uses it
-		if (! $foo = $wpdb->get_row("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%".$wpdb->escape($meta['thumb'])."%' AND post_id <> $postid"))
-			@ unlink(str_replace(basename($file), $meta['thumb'], $file));
+		if (! $wpdb->get_row("SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%".$wpdb->escape($meta['thumb'])."%' AND post_id <> $postid")) {
+			$thumbfile = str_replace(basename($file), $meta['thumb'], $file);
+			$thumbfile = apply_filters('wp_delete_file', $thumbfile);
+			@ unlink($thumbfile);
+		}
 	}
 
+	$file = apply_filters('wp_delete_file', $file);
+
 	if ( ! empty($file) )
 		@ unlink($file);
 
