You are here

function _backup_migrate_temp_files_delete in Backup and Migrate 6.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 backup_migrate.module \_backup_migrate_temp_files_delete()
  6. 6.2 includes/files.inc \_backup_migrate_temp_files_delete()
  7. 7.3 includes/files.inc \_backup_migrate_temp_files_delete()
  8. 7.2 includes/files.inc \_backup_migrate_temp_files_delete()

Delete all temporary files.

2 calls to _backup_migrate_temp_files_delete()
backup_migrate_cleanup in ./backup_migrate.module
Cleanup after a success or failure.
backup_migrate_cron in ./backup_migrate.module
Implementation of hook_cron().
1 string reference to '_backup_migrate_temp_files_delete'
backup_migrate_cleanup in ./backup_migrate.module
Cleanup after a success or failure.

File

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

Code

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

    // 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', 21600);
    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);
    }
  }
}