function backup_migrate_destination_filesource::get_files_to_backup in Backup and Migrate 6.3
Same name and namespace in other branches
- 8.3 includes/sources.filesource.inc \backup_migrate_destination_filesource::get_files_to_backup()
- 7.3 includes/sources.filesource.inc \backup_migrate_destination_filesource::get_files_to_backup()
Get a list of files to backup from the given set if dirs. Exclude any that match the array $exclude.
2 calls to backup_migrate_destination_filesource::get_files_to_backup()
- backup_migrate_destination_filesource::_backup_to_file_php in includes/
sources.filesource.inc - Backup from this source.
- backup_migrate_files_destination_archivesource::_backup_to_file_php in includes/
sources.archivesource.inc - Backup from this source.
File
- includes/
sources.filesource.inc, line 206 - A destination type for saving locally to the server.
Class
- backup_migrate_destination_filesource
- A destination type for saving locally to the server.
Code
function get_files_to_backup($dir, $settings, $exclude = array(), $base_dir = '') {
$out = array();
if (!file_exists($dir)) {
backup_migrate_backup_fail('Directory %dir does not exist.', array(
'%dir' => $dir,
), $settings);
return FALSE;
}
if ($handle = @opendir($dir)) {
while (($file = readdir($handle)) !== FALSE) {
if ($file != '.' && $file != '..' && !in_array($file, $exclude)) {
$file = realpath($dir . '/' . $file);
$path = str_replace($base_dir, '', $file);
// If the path is not excluded.
if (!in_array($path, $exclude)) {
if (is_dir($file)) {
$subdir = $this
->get_files_to_backup($file, $settings, $exclude, $base_dir);
// If there was an error reading the subdirectory then abort the backup.
if ($subdir === FALSE) {
closedir($handle);
return FALSE;
}
// If the directory is empty, add an empty directory.
if (count($subdir) == 0) {
$out[] = $path;
}
$out = array_merge($out, $subdir);
}
else {
if (is_readable($file)) {
$out[] = $path;
}
else {
backup_migrate_backup_fail('The directory cannot be backed up because the file %file cannot be read by the web server.', array(
'%file' => str_replace($base_dir, '', $file),
), $settings);
closedir($handle);
return FALSE;
}
}
}
}
}
closedir($handle);
}
else {
backup_migrate_backup_fail('Could not open directory %dir', array(
'%dir' => $dir,
), $settings);
return FALSE;
}
return $out;
}