Index: modules/file/file.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/file/file.module,v
retrieving revision 1.25
diff -u -p -8 -r1.25 file.module
--- modules/file/file.module	13 Apr 2010 15:23:03 -0000	1.25
+++ modules/file/file.module	14 Apr 2010 07:29:14 -0000
@@ -532,17 +532,17 @@ function file_managed_file_value(&$eleme
 /**
  * An #element_validate callback for the managed_file element.
  */
 function file_managed_file_validate(&$element, &$form_state) {
   // If referencing an existing file, only allow if there are existing
   // references. This prevents unmanaged files from being deleted if this
   // item were to be deleted.
   $clicked_button = end($form_state['clicked_button']['#parents']);
-  if ($clicked_button != 'remove_button' && !empty($element['fid']['#value'])) {
+  if ($clicked_button == 'remove_button' && !empty($element['fid']['#value'])) {
     if ($file = file_load($element['fid']['#value'])) {
       if ($file->status == FILE_STATUS_PERMANENT) {
         $reference_count = 0;
         foreach (module_invoke_all('file_references', $file) as $module => $references) {
           $reference_count += $references;
         }
         if ($reference_count == 0) {
           form_error($element, t('Referencing to the file used in the !name field is not allowed.', array('!name' => $element['#title'])));
