DRUPAL: How To Fix The “Could not delete temporary file” error

For the last year or so I’ve been plagued by “Could not delete temporary file” errors in my Drupal logs after every automatic CRON run.  The entire error(s) look like this:

Type: File System
Message: Could not delete temporary file “/tmp/xyz.jpg” during garbage collection
Severity: emergency
Type: PHP
Message: unlink(/tmp/Snapshot_xyz.jpg) [<a href=’function.unlink’>function.unlink</a>]: Operation not permitted in /includes/file.inc on line 459.
Severity: error

Over time I’ll see more and more of these errors in the DB log, then suddenly they will vanish, then reappear again just as mysteriously after a few days or weeks – and so far none of my Google searches or Drupal.org searches have found a way to clear the errors.  The errors are just an annoyance as everything works just fine, but due to my obsessive-compulsive-stupidity disorder, things like this tend to drive me mad and keep me awake at night.

This evening after dicking around in the database for a few minutes I was finally able to clear these cursed errors – I did two things (which i will outline below) and I’m not sure which of the two actually did the trick, but I’ll post them here for all of you to try.  If you are seeing these errors in your Drupal logs, please try these steps one at a time and post a comment if you are able to determine if either step alone cures the problem.

How to fix the Drupal “Could not delete temporary file during garbage collection” error:

Step 1: Make note of one of the file names specified in the error message.  In your Drupal database, in the FILES table, find and delete the row that contains this particular filename. (note: it’s probably a good idea to make sure you have a backup of your Drupal database before messing with it)

Step 2: While logged-in to your site with User-1/Admin rights, manually run CRON.PHP

That’s it!  Wait until your next automatic CRON.PHP run and (hopefully) all the errors will be gone – not just the error corresponding to the one file you deleted from your Drupal FILES table.

Post your results or, if you have a better way of curing these errors by all means post it.

UPDATE: Turns out you don’t need to mess with your FILES table.  Just running CRON.PHP as USER1 or with ADMIN rights clears this error.. Who’d ‘of thunk it?

5 thoughts on “DRUPAL: How To Fix The “Could not delete temporary file” error

  1. I was getting this same error after a module update. In the database, I found a blank row, and after I deleted it, the error message was gone. Thank you for the idea.

  2. I just try the fix proposed, where we should run the cron trough the user1, and it didn’t work. It may not work for every files in the table…

Leave a Reply to Demiurgos Cancel reply

Your email address will not be published.