You are here

function _cdn_requirements_generate_patterns_for_patch in CDN 6.2

Generate patterns for a patch, given the full path to a patch. This effectively parses the patch and stores it in a meaningful structure.

1 call to _cdn_requirements_generate_patterns_for_patch()
_cdn_requirements_core_patch_patterns in ./cdn.requirements.inc
Generates the patterns for the core patch.

File

./cdn.requirements.inc, line 92
Functionality to automatically detect if a patch has been applied.

Code

function _cdn_requirements_generate_patterns_for_patch($full_path) {

  // The patch file must exist, otherwise we can't generate any patterns.
  if (!file_exists($full_path)) {
    return FALSE;
  }
  $fp = fopen($full_path, 'r');
  $patch_block = '';
  while (!feof($fp)) {
    $line = fgets($fp);

    // Check if the current line indicates the next file.
    if (drupal_substr($line, 0, 13) == 'diff --git a/') {
      $file_to_patch = drupal_substr($line, 13, strpos($line, ' ', 13) - 13);
    }

    // Finally, store the lines that have been added (+): concatenate them in
    // a "patch block".
    if ($line[0] == '+' && ($line[1] == ' ' || $line[1] == "\n")) {
      $patch_block .= drupal_substr($line, 1);
    }
    else {
      if ($patch_block != '') {
        $patterns['core'][$file_to_patch][] = $patch_block;
      }
      $patch_block = '';
    }
  }
  fclose($fp);
  return $patterns;
}