You are here

function backup_migrate_destination_files::check_dir in Backup and Migrate 6.3

Same name and namespace in other branches
  1. 8.2 includes/destinations.file.inc \backup_migrate_destination_files::check_dir()
  2. 8.3 includes/destinations.file.inc \backup_migrate_destination_files::check_dir()
  3. 6.2 includes/destinations.file.inc \backup_migrate_destination_files::check_dir()
  4. 7.3 includes/destinations.file.inc \backup_migrate_destination_files::check_dir()
  5. 7.2 includes/destinations.file.inc \backup_migrate_destination_files::check_dir()

Prepare the destination directory for the backups.

1 call to backup_migrate_destination_files::check_dir()
backup_migrate_destination_files::confirm_destination in includes/destinations.file.inc
Check that a destination is valid.

File

includes/destinations.file.inc, line 201
A destination type for saving locally to the server.

Class

backup_migrate_destination_files
A destination type for saving locally to the server.

Code

function check_dir($directory) {
  $out = TRUE;
  $dirs = array();

  // If the directory doesn't exist try to create it.
  if (!is_dir($directory)) {
    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;
      }
    }
  }

  // Check the write perms on the directory.
  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 ($this
    ->dir_in_webroot($directory)) {
    $directory = $this
      ->check_web_dir($directory);
  }
  return $directory;
}