With a combination of Entity Cache, File Entity and private files:

When using the "replace" file option, users get "access denied" from file_file_download() to the new file because any entities where the file is referenced still have the old file path. The entities need their caches cleared as well.

Here's a workaround for it although a proper patch would probably be better:

/**
 * Implements hook_entity_update().
 */
function modulename_entity_update($entity, $type) {
  if ($type == 'file') {
    // Clear caches of entities where file is used on update.
    foreach (file_usage_list($entity) as $usage) {
      foreach ($usage as $entity_type => $entity_ids) {
        $entity_info = entity_get_info($entity_type);
        $entities = empty($entity_info) ? NULL : entity_load($entity_type, array_keys($entity_ids));
        foreach ($entities as $id => $entity) {
          cache_clear_all($id, 'cache_entity_' . $entity_type);
        }
      }
    }
  }
}

Comments

sheise’s picture

Title: Access denied replacing a file a private file » File access denied after replacing a private file