Improve recursive delete function

Created on 4 March 2021, almost 4 years ago
Updated 6 February 2024, 11 months ago

Problem/Motivation

This is both a bug fix and an improvement.

For the bug fix, the _xmlsitemap_delete_recursive function is a backport of what D7 does for file_unmanaged_delete_recursive. I'm assuming this must have been copied a long time ago, because it references the function as having two parameters, when it currently only has one. Have removed the second parameter.

For the improvement, have modified the return function to check if $path value is empty. We were regularly seeing warning messages in watchdog from xmlsitemap cron runs that "The file was not deleted, because it does not exist.".

Granted, core's file_unmanaged_delete_recursive function will render this warning in watchdog if the $path is empty. However, the xmlsitemap version of this function has already been edited to check if $delete_root exists when running the return drupal_rmdir($path) line.

I think a similar change should be made for the file_unmanaged_delete step to eliminate the extraneous watchdog messages.

Steps to reproduce

Rebuild xmlsitemap for a site that will return an empty path during regeneration.

Proposed resolution

See attached patch.

Remaining tasks

Review patch and provide feedback. Will modify as necessary. Thanks.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

xmlsitemap.module

Created by

πŸ‡ΊπŸ‡ΈUnited States ron_s

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.

  • πŸ‡ΊπŸ‡ΈUnited States douggreen Winchester, VA

    I've seen a similar error in my logs, but I'm on Drupal 10.2.x (not 7.x as this issue is against), so this is not the right fix. And I don't think the problem is passing an empty path to the delete, because my log shows the 1.xml in the path not being deleted.

Production build 0.71.5 2024