Replace the file on disk while running the migration I am changing the migration code (not written by me) to not create new files on migration but to re-use (or rewrite) the existing files.  

The migration code looks like the following:

Source part:

$url = url('filename.json', array('absolute' =&gt; TRUE));
$this-&gt;source = new MigrateSourceJSON(new MultiListJSON($url), 'name', $fields);
$this-&gt;destination = new MigrateDestinationFieldCollection(
  'field_product_documents',
  array('host_entity_type' =&gt; 'node')
);
$this-&gt;map = new MigrateSQLMap($this-&gt;machineName,
  array(
    'name' =&gt; array(
      'type' =&gt; 'varchar',
      'length' =&gt; 255,
      'not null' =&gt; TRUE,
    ),
  ),
 MigrateDestinationFile::getKeySchema()
);


Destination part:

$this-&gt;destination = new MigrateDestinationFile('file', 'MigrateFileBlob');
$this-&gt;addFieldMapping('value', 'blob');
$this-&gt;addFieldMapping('destination_file', 'name');
$this-&gt;addFieldMapping('filename', 'name');
$this-&gt;addFieldMapping('destination_dir' ,'dest_dir')
  -&gt;defaultValue('private://');


This migration is only responsible for creating of the file entities from the blob which comes from a third party service.
There is another migration that is executed after this migration and is responsible for associating the file ids of the files created by this migration.

Following the documentation of the MigrateDestinationFile, the following code could be used to replace the file on the directory:

&lt;?php
    $this-&gt;addFieldMapping('field_my_image:file_replace')
         -&gt;defaultValue(FILE_EXISTS_REPLACE);
?&gt;


But, during the file migration I am not associating it with any field. Hence, it could not be used. Or I am not sure of the exact way to use it.  

My main concern is (let's say) if I have a file ABC.pdf on disk (might not be associated with any entity), the migration should not create a new ABC_0.pdf.

Any pointers would be highly appreciated!
As a temporary fix I have implemented the following in the prepareRow function.

function prepareRow($row) {
  // Delete the file if already present.
  $file_path = drupal_realpath($row-&gt;dest_dir . '/' . $row-&gt;name);
  if (file_exists($file_path)) {
    unlink($file_path);
  }
}


However, I am still not sure about the way it is recommended in the Migrate module.