function backupbuddy_hashGlob($root, $generate_sha1 = true, $excludes = array()) { $files = (array) pb_backupbuddy::$filesystem->deepglob($root); $root_len = strlen($root); $hashedFiles = array(); foreach ($files as $file_id => &$file) { $new_file = substr($file, $root_len); // If this file/directory begins with an exclusion then jump to next file/directory. foreach ($excludes as $exclude) { if (backupbuddy_startsWith($new_file, $exclude)) { continue 2; } } // Omit directories themselves. if (is_dir($file)) { continue; } $stat = stat($file); if (FALSE === $stat) { pb_backupbuddy::status('error', 'Unable to read file `' . $file . '` stat.'); } $hashedFiles[$new_file] = array('size' => $stat['size'], 'modified' => $stat['mtime']); if (true === $generate_sha1 && $stat['size'] < 1073741824) { // < 100mb $hashedFiles[$new_file]['sha1'] = sha1_file($file); } unset($files[$file_id]); // Better to free memory or leave out for performance? } unset($files); return $hashedFiles; }
function backupbuddy_hashGlob($root, $generate_sha1 = false, $excludes = array()) { $root = rtrim($root, '/\\'); // Make sure no trailing slash. $excludes = str_replace($root, '', $excludes); $files = (array) pb_backupbuddy::$filesystem->deepglob($root); $root_len = strlen($root); $hashedFiles = array(); foreach ($files as $file_id => &$file) { $new_file = substr($file, $root_len); // If this file/directory begins with an exclusion then jump to next file/directory. foreach ($excludes as $exclude) { if (backupbuddy_startsWith($new_file, $exclude)) { continue 2; } } // Omit directories themselves. if (is_dir($file)) { continue; } $stat = stat($file); if (FALSE === $stat) { pb_backupbuddy::status('error', 'Unable to read file `' . $file . '` stat. Skipping file.'); continue; } $hashedFiles[$new_file] = array('size' => $stat['size'], 'modified' => $stat['mtime']); if (defined('BACKUPBUDDY_DEV') && true === BACKUPBUDDY_DEV) { $hashedFiles[$new_file]['debug_filename'] = base64_encode($file); $hashedFiles[$new_file]['debug_filelength'] = strlen($file); } if (true === $generate_sha1 && $stat['size'] < 1073741824) { // < 100mb $hashedFiles[$new_file]['sha1'] = sha1_file($file); } unset($files[$file_id]); // Better to free memory or leave out for performance? } unset($files); return $hashedFiles; }