9a10,19
>  * Replace existing files if they are different
>  */
> define('FEEDS_FILE_EXISTS_REPLACE_DIFFERENT', 3);
> 
> /**
>  * Skip Existing Files
>  */
> define('FEEDS_FILE_EXISTS_SKIP', 4);
> 
> /**
23a34,35
>         'summary_callback' => 'file_feeds_summary_callback',
>         'form_callback' => 'file_feeds_form_callback',
51,52c63,67
< function file_feeds_set_target($source, $entity, $target, $value) {
<   if (empty($value)) {
---
> function file_feeds_set_target($source, $entity, $target, $value, $mapping) {
>   $mapping += array('file_exists' => FILE_EXISTS_RENAME);
> 
> 	// If file is empty, feeds tamper (7.x-1.x-dev) passes $value as $value[0] => '' 
>   if(empty($value) || (is_array($value) && empty($value[0]))) {
116a132,157
>         $skip = FALSE;
>         if ($mapping['file_exists'] == FEEDS_FILE_EXISTS_SKIP) {
>           if (file_exists($destination . '/' . basename($v->getValue()))) {
>             $skip = TRUE;
>           }
>           else {
>             // We already know the file doesn't exist so we don't have to
>             // worry about anything being renamed, but we do need a valid
>             // replace value for file_save()
>             $mapping['file_exists'] = FILE_EXISTS_RENAME;
>           }
>         }
>         if ($mapping['file_exists'] == FEEDS_FILE_EXISTS_REPLACE_DIFFERENT && file_exists($destination . '/' . basename($v->getValue()))) {
>           if (file_feeds_file_compare($v->getValue(), $destination . '/' . basename($v->getValue()))) {
>             $skip = TRUE;
>           }
>           else {
>             $mapping['file_exists'] = FILE_EXISTS_REPLACE;
>           }
>         }
>         if ($skip) {
>           // Create a new dummy feeds enclosure where the value is the file
>           // already in the file system (it will be skipped by getFile())
>           $existing_path = $destination . '/' . basename($v->getValue());
>           $v = new FeedsEnclosure($existing_path, file_get_mimetype($existing_path));
>         }
118c159
<           $file = $v->getFile($destination);
---
>           $file = $v->getFile($destination, $mapping['file_exists']);
132a174,239
> }
> 
> /**
>  * Mapping configuration summary callback.
>  */
> function file_feeds_summary_callback($mapping, $target, $form, $form_state) {
>   $mapping += array('file_exists' => FILE_EXISTS_RENAME);
>   switch ($mapping['file_exists']) {
>     case FILE_EXISTS_REPLACE:
>       return t('Replace existing files');
> 
>     case FILE_EXISTS_RENAME:
>       return t('Rename if file exists');
> 
>     case FEEDS_FILE_EXISTS_REPLACE_DIFFERENT:
>       return t('Replace if file exists but is different');
> 
>     case FEEDS_FILE_EXISTS_SKIP:
>       return t('Skip if file exists');
>   }
> }
> 
> /**
>  * Settings form callback.
>  */
> function file_feeds_form_callback($mapping, $target, $form, $form_state) {
>   return array(
>     'file_exists' => array(
>       '#type' => 'select',
>       '#title' => t('Replacement method'),
>       '#default_value' => !empty($mapping['file_exists']) ? $mapping['file_exists'] : FILE_EXISTS_RENAME,
>       '#options' => array(
>         FILE_EXISTS_RENAME => t('Rename'),
>         FILE_EXISTS_REPLACE => t('Replace'),
>         FEEDS_FILE_EXISTS_REPLACE_DIFFERENT => t('Replace if different'),
>         FEEDS_FILE_EXISTS_SKIP => t('Skip existing'),
>       ),
>     ),
>   );
> }
> 
> /**
>  * Compares two files to determine if they are the same.
>  *
>  * @param string $file1
>  *   The path to the first file to compare
>  *
>  * @param string $file2
>  *   The path to the second file to compare
>  *
>  * @return boolean
>  *   Returns TRUE if the files are the same or FALSE if they're different
>  */
> function file_feeds_file_compare($file1, $file2) {
> 
>   // Simple file size check first
>   if (filesize($file1) !== filesize($file2)) {
>     return FALSE;
>   }
> 
>   // Calculate md5
>   if (md5_file($file1) !== md5_file($file2)) {
>     return FALSE;
>   }
> 
>   return TRUE;
