You are here

function acquia_spi_hash_path in Acquia Connector 6.2

Same name and namespace in other branches
  1. 6 acquia_spi/acquia_spi.module \acquia_spi_hash_path()
  2. 7.3 acquia_spi/acquia_spi.module \acquia_spi_hash_path()
  3. 7 acquia_spi/acquia_spi.module \acquia_spi_hash_path()
  4. 7.2 acquia_spi/acquia_spi.module \acquia_spi_hash_path()

Calculate the sha1 hash for a path.

Parameters

$path: The name of the file or a directory.

Return value

bas64 encoded sha1 hash. 'hash' is an empty string for directories.

1 call to acquia_spi_hash_path()
_acquia_spi_generate_hashes in acquia_spi/acquia_spi.module
Recursive helper function for acquia_spi_file_hashes().

File

acquia_spi/acquia_spi.module, line 1635
Send site profile information (NSPI) and system data to Acquia Insight.

Code

function acquia_spi_hash_path($path = '') {
  $hash = '';
  if (file_exists($path)) {
    if (!is_dir($path)) {
      $string = file_get_contents($path);

      // Remove trailing whitespace
      $string = rtrim($string);

      // Replace all line endings and CVS/svn Id tags
      $string = preg_replace('/\\$Id[^;<>{}\\(\\)\\$]*\\$/', 'x$' . 'Id$', $string);
      $string = preg_replace('/\\r\\n|\\n|\\r/', ' ', $string);
      $hash = base64_encode(pack("H*", sha1($string)));
    }
  }
  return $hash;
}