This commit introduced a mechanism to preserve mtime in Doxygen-generated XML files in order to avoid having to process unchanged files every time we incrementally build the doc. More info can be found in this thread.
The dirsync library seems up to the task, so potentially it could be used to replace much of the code in the script.