file_cron() will log an error if the file it's trying to delete does not exist. However, if it does not exist, it would be more appropriate to delete the entity and log a warning.
Suggesting change from:
function file_cron()
...
if (empty($references)) {
if (file_exists($file->getFileUri())) {
$file->delete();
}
else {
\Drupal::logger('file system')->error('Could not delete temporary file "%path" during garbage collection', array('%path' => $file->getFileUri()));
}
}
to:
if (empty($references)) {
if (file_exists($file->getFileUri())) {
$file->delete();
}
else {
//go ahead and delete the entity, even though the file does not exist
$file->delete();
\Drupal::logger('file system')->warning('During garbage collection the temporary file "%path" did not exist.', array('%path' => $file->getFileUri()));
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | drupal-add-warning-2760347-11.D8.patch | 2.96 KB | thelmer |
| #3 | add-warning-2760347-3.patch | 653 bytes | kamalrajsahu21 |
Comments
Comment #2
ecrutchfield commentedComment #3
kamalrajsahu21 commentedHere is the path with warning message changed to "Could not find temporary file "%path" during garbage collection".
Comment #4
kamalrajsahu21 commentedComment #5
ecrutchfield commentedThanks for taking a look at the issue, and certainly changing the message is a good first step. But why wouldn't you go ahead and delete the file from the table if it wasn't found?
Comment #6
kamalrajsahu21 commentedI believe it's good to delete from table if file is not found because there is no use of it.
Comment #7
ecrutchfield commentedSorry, I misread your patch so that looks good to me. Thanks for taking care of that.
Comment #8
ecrutchfield commentedI've reviewed the patch and all looks good. Do I need to do something with the issue status?
Comment #10
thelmer commentedNeeds test, will start working an this
Comment #11
thelmer commentedComment #12
alexpott@thelmer, thanks for working on this issue. After working on patch the correct status to get a review is needs review.
Also given #2801777: Give users the option to prevent drupal from automatically marking unused files as temporary we need sub system maintainer review.
Out of scope chnages - coding standards should be fixed in other issues.
Comment #14
berdirI merged the test into #2760347: file_cron does not remove orphaned entries and requested that you get credited there.
Comment #15
kalistos commentedBerdir pointed incorrect link for duplicated issue. Correct link: #2802803: Temporary files whose files are missing on the disk result in never-ending error log messages