diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-07-10 01:57:32 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-07-10 01:57:32 +0000 |
commit | 3e44e9eed677f71329bbdcdfe6db4032578c9111 (patch) | |
tree | 448584d2c6a694da01028f56d7aa1d8bf154fb94 | |
parent | 57ab633bc52c08aacc0463d496ff09f034e0f8d1 (diff) | |
download | brdo-3e44e9eed677f71329bbdcdfe6db4032578c9111.tar.gz brdo-3e44e9eed677f71329bbdcdfe6db4032578c9111.tar.bz2 |
- Patch #819388 by pwolanin: switch registry back to using hashes not file mtime and ctime.
-rw-r--r-- | includes/registry.inc | 22 | ||||
-rw-r--r-- | includes/update.inc | 3 | ||||
-rw-r--r-- | modules/simpletest/tests/registry.test | 15 | ||||
-rw-r--r-- | modules/system/system.install | 14 |
4 files changed, 18 insertions, 36 deletions
diff --git a/includes/registry.inc b/includes/registry.inc index 7b54e4833..9a12e393f 100644 --- a/includes/registry.inc +++ b/includes/registry.inc @@ -65,11 +65,9 @@ function _registry_update() { // or modify attributes of a file. drupal_alter('registry_files', $files, $modules); foreach (registry_get_parsed_files() as $filename => $file) { - // Add the file creation and modification dates to those files we have - // already parsed. + // Add the hash for those files we have already parsed. if (isset($files[$filename])) { - $files[$filename]['filectime'] = $file['filectime']; - $files[$filename]['filemtime'] = $file['filemtime']; + $files[$filename]['hash'] = $file['hash']; } else { // Flush the registry of resources in files that are no longer on disc @@ -129,22 +127,15 @@ function registry_get_parsed_files() { */ function _registry_parse_files($files) { $parsed_files = array(); - $filetimes = array(); foreach ($files as $filename => $file) { if (file_exists($filename)) { - $filetimes[$filename] = array( - 'filectime' => filectime($filename), - 'filemtime' => filemtime($filename), - ); - - $modified_file = !isset($file['filectime']) || !isset($file['filemtime']) - || $filetimes[$filename]['filectime'] != $file['filectime'] - || $filetimes[$filename]['filemtime'] != $file['filemtime']; - if ($modified_file) { + $hash = hash_file('sha256', $filename); + if (empty($file['hash']) || $file['hash'] != $hash) { // Delete registry entries for this file, so we can insert the new resources. db_delete('registry') ->condition('filename', $filename) ->execute(); + $file['hash'] = $hash; $parsed_files[$filename] = $file; } } @@ -154,8 +145,7 @@ function _registry_parse_files($files) { db_merge('registry_file') ->key(array('filename' => $filename)) ->fields(array( - 'filectime' => $filetimes[$filename]['filectime'], - 'filemtime' => $filetimes[$filename]['filemtime'], + 'hash' => $file['hash'], )) ->execute(); } diff --git a/includes/update.inc b/includes/update.inc index c3fde15b1..3cd6b76c3 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -141,8 +141,7 @@ function update_prepare_d7_bootstrap() { $schema['registry_file'] = array( 'fields' => array( 'filename' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE), - 'filectime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), - 'filemtime' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'hash' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), ), 'primary key' => array('filename'), ); diff --git a/modules/simpletest/tests/registry.test b/modules/simpletest/tests/registry.test index 81bcfd8ef..10b04578d 100644 --- a/modules/simpletest/tests/registry.test +++ b/modules/simpletest/tests/registry.test @@ -71,10 +71,11 @@ class RegistryParseFilesTestCase extends DrupalWebTestCase { file_save_data($this->$fileType->contents, $this->$fileType->fileName); if ($fileType == 'existing_changed') { + // Add a record with an incorrect hash. + $this->$fileType->fakeHash = hash('sha256', mt_rand()); db_insert('registry_file') ->fields(array( - 'filectime' => mt_rand(1, 1000000), - 'filemtime' => mt_rand(1, 1000000), + 'hash' => $this->$fileType->fakeHash, 'filename' => $this->$fileType->fileName, )) ->execute(); @@ -104,10 +105,9 @@ class RegistryParseFilesTestCase extends DrupalWebTestCase { $foundName = db_query('SELECT name FROM {registry} WHERE name = :name', array(':name' => $this->$fileType->$resource))->fetchField(); $this->assertTrue($this->$fileType->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$fileType->$resource))); } - // Test that we have the right file creation and modification dates. - $dates = db_query('SELECT filectime, filemtime FROM {registry_file} WHERE filename = :filename', array(':filename' => $this->$fileType->fileName))->fetchObject(); - $this->assertEqual($dates->filectime, filectime($this->$fileType->fileName), t('File creation date matches for %filename.', array('%filename' => $this->$fileType->fileName))); - $this->assertEqual($dates->filemtime, filemtime($this->$fileType->fileName), t('File modification date matches for %filename.', array('%filename' => $this->$fileType->fileName))); + // Test that we have the right hash. + $hash = db_query('SELECT hash FROM {registry_file} WHERE filename = :filename', array(':filename' => $this->$fileType->fileName))->fetchField(); + $this->assertTrue(hash('sha256', $this->$fileType->contents) == $hash, t('sha-256 for "@filename" matched.' . $fileType . $hash, array('@filename' => $this->$fileType->fileName))); } } @@ -119,8 +119,7 @@ class RegistryParseFilesTestCase extends DrupalWebTestCase { foreach ($this->fileTypes as $fileType) { $files[$this->$fileType->fileName] = array('module' => '', 'weight' => 0); if ($fileType == 'existing_changed') { - $files[$this->$fileType->fileName]['filectime'] = mt_rand(1, 1000000); - $files[$this->$fileType->fileName]['filemtime'] = mt_rand(1, 1000000); + $files[$this->$fileType->fileName]['hash'] = $this->$fileType->fakeHash; } } return $files; diff --git a/modules/system/system.install b/modules/system/system.install index aa42738c8..47b04d1f2 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -1346,17 +1346,11 @@ function system_schema() { 'length' => 255, 'not null' => TRUE, ), - 'filectime' => array( - 'description' => "The creation time of the file when last parsed.", - 'type' => 'int', - 'not null' => TRUE, - 'default' => 0, - ), - 'filemtime' => array( - 'description' => "The modification time of the file when last parsed.", - 'type' => 'int', + 'hash' => array( + 'description' => "sha-256 hash of the file's contents when last parsed.", + 'type' => 'varchar', + 'length' => 64, 'not null' => TRUE, - 'default' => 0, ), ), 'primary key' => array('filename'), |