You are here

function advagg_checksum in Advanced CSS/JS Aggregation 6

Same name and namespace in other branches
  1. 7 advagg.module \advagg_checksum()

Generate a checksum for a given filename.

Parameters

$filename: filename

Return value

Checksum value.

2 calls to advagg_checksum()
advagg_flush_caches in ./advagg.module
Implementation of hook_flush_caches().
advagg_insert_bundle_db in ./advagg.module
Insert info into the advagg_files and advagg_bundles database.

File

./advagg.module, line 1486
Advanced CSS/JS aggregation module

Code

function advagg_checksum($filename) {
  advagg_clearstatcache(TRUE, $filename);
  if (file_exists($filename)) {
    $mode = variable_get('advagg_checksum_mode', ADVAGG_CHECKSUM_MODE);
    if ($mode == 'mtime') {
      $checksum = @filemtime($filename);
      if ($checksum === FALSE) {
        touch($filename);
        advagg_clearstatcache(TRUE, $filename);
        $checksum = @filemtime($filename);

        // Use md5 as a last option.
        if ($checksum === FALSE) {
          $checksum = md5(file_get_contents($filename));
        }
      }
    }
    elseif ($mode == 'md5') {
      $checksum = md5(file_get_contents($filename));
    }
  }
  else {
    $checksum = '-1';
  }
  return $checksum;
}