file_cron ceases to delete files if more than 100 file entities fail file_exists($file->getFileUri())

Created on 20 December 2017, almost 7 years ago
Updated 1 May 2023, over 1 year ago

During file_cron, while query the file entities, suitable for deletion, it sorts the query based on the defaults, which has a habbit of grabbing the oldest entities first.

Our issue was, during development we had lots of file entites that were created, but the files were removed from disk. So when file_exists($file->getFileUri()) == false, none of these files are deleted and it throws an exception. And this is a sane usage.

I propose though, we add an explicit sort based on the changed property. This way at least if you a lot of files which need clean up. It's run on the newest/updated items first, and won't continue to worsen the situation.

🐛 Bug report
Status

Needs work

Version

9.5

Component
File system 

Last updated about 11 hours ago

Created by

🇺🇸United States richard.c.allen2386

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇮🇳India nikhil_110

    Attached patch against Drupal 9.5.x
    Patch #8 is not applied for Drupal 9.5.x so Inter-diff file is not added.

    error: while searching for:
          ->condition('status', FileInterface::STATUS_PERMANENT, '<>')
          ->condition('changed', REQUEST_TIME - $age, '<')
          ->range(0, 100)
          ->execute();
        $files = $file_storage->loadMultiple($fids);
        foreach ($files as $file) {
    
    error: patch failed: core/modules/file/file.module:648
    error: core/modules/file/file.module: patch does not apply
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    30,322 pass
Production build 0.71.5 2024