Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

file_delete() in Drupal 7.x contains checks whether the file being deleted has any remaining usages registered and if so, the deletion was aborted. This check has been removed as preparation for the classed entity conversion.

To simplify the API and prevent incorrectly deleted files, file_usage()->add() now ensures that a file is permanent and file_usage()->delete() now makes a file temporary again if all usages are removed. Temporary files are then removed during cron after 6 hours. It is no longer necessary to explicitly delete a file entity when relying on the file usage API, which is recommended.

Drupal 7:

// When adding a file.
file_usage_add($file, 'mymodule', 'node', 1);
$file->status = FILE_STATUS_PERMANENT;
file_save($file);

// When removing a file.
file_usage_delete($file, 'mymodule', 'node', 1);
file_delete($file);

Drupal 8:

// When adding a file.
file_usage()->add($file, 'mymodule', 'node', 1);

// When removing a file.
file_usage()->delete($file, 'mymodule', 'node', 1);
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done