hook_file_presave – Any way to get the parent $entity that you are modifying the file_field on?

I’m trying to alter the behavior of file uploads on a node using the file field to allow users to be able to replace files preserving the filename in the file system url. I have it working except I need to add some logic to check to see if the filename being uploaded is being used on another node. How should I do this?

My logic for the forcing of the uploaded filename is in hook_file_presave and there doesn’t seem to be any information about the node being edited in the $file entity in my presave function.

Here is the code I’ve written so far:

 * Implements hook_file_presave().
function sfwmd_file_presave(DrupalfileFileInterface $file) {

  $FileNameExistsOnCurrentNodeOnly = '..... Some logic to check whether the filename already exists on node of type document';

  if ($file->isNewRevision() == 1 && $FileNameExistsOnCurrentNodeOnly){
    $uploaded_filename = $file->getFilename();
    $old_uri = $file->getFileUri();

    $path = pathinfo($old_uri);
    $new_uri = $path['dirname'] . '/' . $uploaded_filename;

    # Copy the uploaded file over the original
    if ($old_uri != $new_uri) {

      file_unmanaged_copy($old_uri, $new_uri, FILE_EXISTS_REPLACE);
      #drupal_set_message('Copying '.$old_uri.' -> '.$new_uri);

      # Set the new file name to the original

      drupal_set_message('File Overwritten');



Drupal version: 

Source: https://www.drupal.org/taxonomy/term/4/feed