You are here

function _backup_migrate_destination_file_check_dir in Backup and Migrate 5.2

Prepare the destination directory for the backups.

2 calls to _backup_migrate_destination_file_check_dir()
backup_migrate_destination_file_save in includes/destinations.file.inc
File save destination callback.
_backup_migrate_check_destination_dir in includes/destinations.file.inc
Check the default backup desitantion directory. Included as legacy support.

File

includes/destinations.file.inc, line 77
Functions to handle the local server directory backup destinations.

Code

function _backup_migrate_destination_file_check_dir($directory) {
  $out = TRUE;
  $dirs = array();
  foreach (explode('/', $directory) as $dir) {
    $dirs[] = $dir;
    $path = implode($dirs, '/');
    if ($path && !is_dir(realpath($path)) && !file_check_directory($path, FILE_CREATE_DIRECTORY)) {
      $out = FALSE;
    }
  }
  if (!$out || !file_check_directory($directory)) {

    // Unable to create destination directory.
    _backup_migrate_message("Unable to create or write to the save directory '%directory'. Please check the file permissions that directory and try again.", array(
      '%directory' => $directory,
    ), "error");
    return FALSE;
  }

  // If the destination directory is within the webroot, then secure it as best we can.
  if (_backup_migrate_dir_in_webroot($directory)) {
    $directory = _backup_migrate_destination_file_check_web_dir($directory);
  }
  return $directory;
}