You are here

function _backup_migrate_temp_files_delete in Backup and Migrate 7.3

Same name and namespace in other branches
  1. 8.2 includes/files.inc \_backup_migrate_temp_files_delete()
  2. 8.3 includes/files.inc \_backup_migrate_temp_files_delete()
  3. 5.2 includes/files.inc \_backup_migrate_temp_files_delete()
  4. 5 backup_migrate.module \_backup_migrate_temp_files_delete()
  5. 6.3 includes/files.inc \_backup_migrate_temp_files_delete()
  6. 6 backup_migrate.module \_backup_migrate_temp_files_delete()
  7. 6.2 includes/files.inc \_backup_migrate_temp_files_delete()
  8. 7.2 includes/files.inc \_backup_migrate_temp_files_delete()

Delete all temporary files.

3 calls to _backup_migrate_temp_files_delete()
backup_migrate_cleanup in ./backup_migrate.module
Cleans up after a success or failure.
backup_migrate_cron in ./backup_migrate.module
Implements hook_cron().
backup_migrate_destination::list_files in includes/destinations.inc
List all the available files in the given destination.
1 string reference to '_backup_migrate_temp_files_delete'
backup_migrate_cleanup in ./backup_migrate.module
Cleans up after a success or failure.

File

includes/files.inc, line 26
General file handling code for Backup and Migrate.

Code

function _backup_migrate_temp_files_delete() {
  if (variable_get('backup_migrate_cleanup_temp_files', BACKUP_MIGRATE_CLEANUP_TEMP_FILES)) {

    // Delete the temp files created during this run.
    foreach (backup_migrate_temp_files_add() as $file) {
      if (file_exists($file) && is_writable($file)) {
        _backup_migrate_temp_files_delete_file($file);
      }
    }

    // Delete temp files abandoned for 6 or more hours.
    $dir = file_directory_temp();
    $expire = time() - variable_get('backup_migrate_cleanup_time', BACKUP_MIGRATE_CLEANUP_TIME);
    if (file_exists($dir) && is_dir($dir) && is_readable($dir) && ($handle = opendir($dir))) {
      while (FALSE !== ($file = @readdir($handle))) {

        // Delete 'backup_migrate_' files in the temp directory that are older than the expire time.
        // We should only attempt to delete writable files to prevent errors in shared environments.
        // This could still cause issues in shared environments with poorly configured file permissions.
        if (strpos($file, 'backup_migrate_') === 0 && is_writable("{$dir}/{$file}") && @filectime("{$dir}/{$file}") < $expire) {
          _backup_migrate_temp_files_delete_file("{$dir}/{$file}");
        }
      }
      closedir($handle);
    }
  }
}