file_exists() doesn't work with remote stream wrappers in file_cron()

Created on 6 December 2017, over 7 years ago
Updated 13 June 2025, 11 days ago

As the title says there is a file_exists() call in file_cron. Unfortunately :) this logs an error because it always returns false, and it makes it not possible to remove remote files on cleanup.

🐛 Bug report
Status

Postponed

Version

11.0 🔥

Component

file system

Created by

🇬🇧United Kingdom kalpaitch

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇮🇳India mohit_aghera Rajkot

    This seems to have been refactored and we are checking if file exists based on wrapper.

    https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/file/...
    Following is the latest code:

    if (!file_exists($file->getFileUri())) {
                if (!$this->streamWrapperManager->isValidUri($file->getFileUri())) {
                  $this->logger->warning('Temporary file "%path" that was deleted during garbage collection did not exist on the filesystem. This could be caused by a missing stream wrapper.', ['%path' => $file->getFileUri()]);
                }
                else {
                  $this->logger->warning('Temporary file "%path" that was deleted during garbage collection did not exist on the filesystem.', ['%path' => $file->getFileUri()]);
                }
              }
              // Delete the file entity. If the file does not exist, this will
              // generate a second notice in the watchdog.
              $file->delete();
    

    Here if file doesn't exist, we are adding errors in the log.

    Do we explicitly need to add a new try-catch now?

Production build 0.71.5 2024