diff --git a/file_entity.file.inc b/file_entity.file.inc index c9aab5c..db6fdef 100644 --- a/file_entity.file.inc +++ b/file_entity.file.inc @@ -105,8 +105,10 @@ function file_entity_file_update($file) { _file_entity_update_image_field_dimensions($file); } - // Flush image style derivatives whenever an image is updated. - image_path_flush($file->uri); + // Flush image style derivatives whenever an image is replaced. + if (empty($file->file_entity_skip_image_flush) && file_entity_has_file_changed($file)) { + image_path_flush($file->uri); + } } // Clear any related field caches. @@ -114,6 +116,14 @@ function file_entity_file_update($file) { } /** + * Returns whether the file has changed + */ +function file_entity_has_file_changed($file) { + return empty($file->original) || $file->filesize != $file->original->filesize || $file->uri != $file->original->uri; +} + + +/** * Implements hook_file_delete(). */ function file_entity_file_delete($file) { diff --git a/file_entity.pages.inc b/file_entity.pages.inc index f885d4d..76e94ac 100644 --- a/file_entity.pages.inc +++ b/file_entity.pages.inc @@ -443,6 +443,8 @@ function file_entity_add_upload_submit($form, &$form_state) { // the fields are on the last page of the multi step form. entity_form_submit_build_entity('file', $file, $form, $form_state); + // This is a new file, skip flushing imagecache. + $file->file_entity_skip_image_flush = TRUE; file_save($file); $form_state['file'] = $file; drupal_set_message(t('@type %name was uploaded.', array('@type' => file_entity_type_get_name($file), '%name' => $file->filename)));