Code Duplication    Length = 39-42 lines in 2 locations

wp-admin/includes/update-core.php 1 location

@@ 1148-1189 (lines=42) @@
1145
 * @param array $skip_list a list of files/folders to skip copying
1146
 * @return mixed WP_Error on failure, True on success.
1147
 */
1148
function _copy_dir($from, $to, $skip_list = array() ) {
1149
	global $wp_filesystem;
1150
1151
	$dirlist = $wp_filesystem->dirlist($from);
1152
1153
	$from = trailingslashit($from);
1154
	$to = trailingslashit($to);
1155
1156
	foreach ( (array) $dirlist as $filename => $fileinfo ) {
1157
		if ( in_array( $filename, $skip_list ) )
1158
			continue;
1159
1160
		if ( 'f' == $fileinfo['type'] ) {
1161
			if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
1162
				// If copy failed, chmod file to 0644 and try again.
1163
				$wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
1164
				if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
1165
					return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
1166
			}
1167
		} elseif ( 'd' == $fileinfo['type'] ) {
1168
			if ( !$wp_filesystem->is_dir($to . $filename) ) {
1169
				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
1170
					return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
1171
			}
1172
1173
			/*
1174
			 * Generate the $sub_skip_list for the subdirectory as a sub-set
1175
			 * of the existing $skip_list.
1176
			 */
1177
			$sub_skip_list = array();
1178
			foreach ( $skip_list as $skip_item ) {
1179
				if ( 0 === strpos( $skip_item, $filename . '/' ) )
1180
					$sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
1181
			}
1182
1183
			$result = _copy_dir($from . $filename, $to . $filename, $sub_skip_list);
1184
			if ( is_wp_error($result) )
1185
				return $result;
1186
		}
1187
	}
1188
	return true;
1189
}
1190
1191
/**
1192
 * Redirect to the About WordPress page after a successful upgrade.

wp-admin/includes/file.php 1 location

@@ 829-867 (lines=39) @@
826
 * @param array $skip_list a list of files/folders to skip copying
827
 * @return mixed WP_Error on failure, True on success.
828
 */
829
function copy_dir($from, $to, $skip_list = array() ) {
830
	global $wp_filesystem;
831
832
	$dirlist = $wp_filesystem->dirlist($from);
833
834
	$from = trailingslashit($from);
835
	$to = trailingslashit($to);
836
837
	foreach ( (array) $dirlist as $filename => $fileinfo ) {
838
		if ( in_array( $filename, $skip_list ) )
839
			continue;
840
841
		if ( 'f' == $fileinfo['type'] ) {
842
			if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
843
				// If copy failed, chmod file to 0644 and try again.
844
				$wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
845
				if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
846
					return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
847
			}
848
		} elseif ( 'd' == $fileinfo['type'] ) {
849
			if ( !$wp_filesystem->is_dir($to . $filename) ) {
850
				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
851
					return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );
852
			}
853
854
			// generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list
855
			$sub_skip_list = array();
856
			foreach ( $skip_list as $skip_item ) {
857
				if ( 0 === strpos( $skip_item, $filename . '/' ) )
858
					$sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
859
			}
860
861
			$result = copy_dir($from . $filename, $to . $filename, $sub_skip_list);
862
			if ( is_wp_error($result) )
863
				return $result;
864
		}
865
	}
866
	return true;
867
}
868
869
/**
870
 * Initialises and connects the WordPress Filesystem Abstraction classes.