From 3913d6a97e087f931cdad5adb8977513a0d5f9e0 Mon Sep 17 00:00:00 2001
From: Vincent Massaro <vincent.massaro@yale.edu>
Date: Fri, 15 Mar 2013 16:06:11 -0400
Subject: [PATCH] Combined patches #19 and #25 from drupal.org/node/1171114

---
 mappers/file.inc        | 2 +-
 plugins/FeedsParser.inc | 7 +++++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/mappers/file.inc b/mappers/file.inc
index 646d055..2c099c4 100644
--- a/mappers/file.inc
+++ b/mappers/file.inc
@@ -77,7 +77,7 @@ function file_feeds_set_target($source, $entity, $target, $value) {
   $field = isset($entity->$target) ? $entity->$target : array();
   foreach ($value as $v) {
     try {
-      $file = $v->getFile($destination);
+      $file = $v->getFile($destination, FILE_EXISTS_REPLACE);
     }
     catch (Exception $e) {
       watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
diff --git a/plugins/FeedsParser.inc b/plugins/FeedsParser.inc
index 8772e32..b53da92 100644
--- a/plugins/FeedsParser.inc
+++ b/plugins/FeedsParser.inc
@@ -332,6 +332,9 @@ class FeedsEnclosure extends FeedsElement {
    * @param $destination
    *   The path or uri specifying the target directory in which the file is
    *   expected. Don't use trailing slashes unless it's a streamwrapper scheme.
+   * @param $replace
+   *   Replace behavior when the destination file already exists.
+   *   @see file_save_data
    *
    * @return
    *   A Drupal temporary file object of the enclosed resource.
@@ -339,7 +342,7 @@ class FeedsEnclosure extends FeedsElement {
    * @throws Exception
    *   If file object could not be created.
    */
-  public function getFile($destination) {
+  public function getFile($destination, $replace = FILE_EXISTS_RENAME) {
 
     if ($this->getValue()) {
       // Prepare destination directory.
@@ -377,7 +380,7 @@ class FeedsEnclosure extends FeedsElement {
           $destination = trim($destination, '/') . '/';
         }
         try {
-          $file = file_save_data($this->getContent(), $destination . $filename);
+          $file = file_save_data($this->getContent(), $destination . $filename, $replace);
         }
         catch (Exception $e) {
           watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
-- 
1.8.0

