public/wordpress/wp-content/plugins/backupbuddy/classes/core.php
/* hashGlob()
	 *
	 * Calculate comparison data for all files within a path. Useful for tracking file changes between two locations.
	 *
	 * @param  string $root            ABSOLUTE full path.
	 * @param  array  $excludes        Directories to exclude, RELATIVE to the root. Include LEADING slash for each entry.
	 * @param  array  $utf8_encode	Should we encode any file names that are in UTF-8 format?
	 * @param  string $prependPath	String path to prepend in the resulting array key returned. Does not impact actual calculations.
	 * @return array 				Nested array of file/directory structure.
	 */
hashGlob()
Calculate comparison data for all files within a path. Useful for tracking file changes between two locations.

@param  string $root            ABSOLUTE full path.
@param  array  $excludes        Directories to exclude, RELATIVE to the root. Include LEADING slash for each entry.
@param  array  $utf8_encode  Should we encode any file names that are in UTF-8 format.
@param  string $prependPath  String path to prepend in the resulting array key returned. Does not impact actual calculations.
@return array                                Nested array of file/directory structure.
hashGlob () Calculate comparison data for all files within a path . Useful for tracking file changes between two locations . @param string $root ABSOLUTE full path . @param array $excludes Directories to exclude RELATIVE to the root . Include LEADING slash for each entry . @param array $utf8_encode Should we encode any file names that are in UTF - 8 format . @param string $prependPath String path to prepend in the resulting array key returned . Does not impact actual calculations . @return array Nested array of file / directory structure .
public static function hashGlob( $root, $generate_sha1 = false, $excludes = array(), $utf8_encode = false, $prependPath = '' ) {
		$root = rtrim( $root, '/\\' ); 
		$excludes = str_replace( $root, '', $excludes ); 
		if ( ! file_exists( $root ) ) {
			pb_backupbuddy::status( 'warning', 'Warning #8949834934: Unable to read hashGlob of dir as it does not exist: `' . $root . '`. SKIPPING OVER.' );
			return array();
		}
		$files = (array) pb_backupbuddy::$filesystem->deepscandir( $root ); 
		$root_len = strlen( $root );
		$hashedFiles = array();
		foreach( $files as $file_id => &$file ) {
			$new_file = substr( $file, $root_len );
			foreach( $excludes as $exclude ) {
				if ( backupbuddy_core::startsWith( $new_file, $exclude ) ) {
					continue 2;
				}
			}
			if ( is_dir( $file ) ) {
				continue;
			}
			$stat = stat( $file );
			if ( FALSE === $stat ) {
				pb_backupbuddy::status( 'error', 'Unable to read file `' . $file . '` stat. Skipping file.' );
				continue;
			}
			if ( $utf8_encode && ( 'UTF-8' == mb_detect_encoding( $new_file ) ) ) {
				$new_file = utf8_encode( $new_file );
			}
			$new_file = $prependPath . $new_file;
			$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 ) ) { 
				$hashedFiles[$new_file]['sha1'] = sha1_file( $file );
			}
			unset( $files[$file_id] ); 			
		}
		unset( $files );
		return $hashedFiles;
	}
public static function hashGlob ( $ root , $ generate_sha1 = false , $ excludes = array ( ) , $ utf8_encode = false , $ prependPath = '' ) { $ root = rtrim ( $ root , '/\\' ) ; $ excludes = str_replace ( $ root , '' , $ excludes ) ; if ( ! file_exists ( $ root ) ) { pb_backupbuddy :: status ( 'warning' , 'Warning #8949834934: Unable to read hashGlob of dir as it does not exist: `' . $ root . '`. SKIPPING OVER.' ) ; return array ( ) ; } $ files = ( array ) pb_backupbuddy :: $ filesystem -> deepscandir ( $ root ) ; $ root_len = strlen ( $ root ) ; $ hashedFiles = array ( ) ; foreach ( $ files as $ file_id => & $ file ) { $ new_file = substr ( $ file , $ root_len ) ; foreach ( $ excludes as $ exclude ) { if ( backupbuddy_core :: startsWith ( $ new_file , $ exclude ) ) { continue 2 ; } } if ( is_dir ( $ file ) ) { continue ; } $ stat = stat ( $ file ) ; if ( FALSE === $ stat ) { pb_backupbuddy :: status ( 'error' , 'Unable to read file `' . $ file . '` stat. Skipping file.' ) ; continue ; } if ( $ utf8_encode && ( 'UTF-8' == mb_detect_encoding ( $ new_file ) ) ) { $ new_file = utf8_encode ( $ new_file ) ; } $ new_file = $ prependPath . $ new_file ; $ 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 ) ) { $ hashedFiles [ $ new_file ] [ 'sha1' ] = sha1_file ( $ file ) ; } unset ( $ files [ $ file_id ] ) ; } unset ( $ files ) ; return $ hashedFiles ; }
hashGlob()
 Calculate comparison data for all files within a path.
hashGlob () Calculate comparison data for all files within a path .
//error_log( 'excludes:' ); //error_log( print_r( $excludes, true ) ); // Make sure no trailing slash. // Make sure all relative to the root. // As of v7.0 changed from deepscan to deepglob to get any dirs or files beginning with a period. // If this file/directory begins with an exclusion then jump to next file/directory. // Omit directories themselves. // If the filename is in UTF-8 and the flag is set, encode before using as an array key // < 100mb // Better to free memory or leave out for performance?
