Verified Commit 61ef4c65 authored by godotislate's avatar godotislate
Browse files

task: #3589208 Always use the file contents to determine asset aggregate filename hashes

By: catch
By: smustgrave
By: alexpott
By: heddn
By: godotislate
parent b5b29d41
Loading
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -36,12 +36,14 @@ protected function generateHash(array $group): string {
    ];
    foreach ($group['items'] as $key => $asset) {
      $normalized['asset_group']['items'][$key] = array_diff_key($asset, $group_keys, $omit_keys);
      // If the version is set to -1, this means there is no version in the
      // library definition. To ensure unique hashes when unversioned files
      // change, replace the version with a hash of the file contents.
      if ($asset['version'] === -1) {
        $normalized['asset_group']['items'][$key]['version'] = hash('xxh64', file_get_contents($asset['data']));
      }

      // Drupal core adds a version to libraries even when they don't change.
      // Conversely some themes or modules may fail to update the version when
      // files do change. Therefore always replace the version with a hash of
      // the file contents so that it always, but only, updates when the file
      // itself changes. Check for file existence here because missing files
      // should be dealt with elsewhere than when generating the hash.
      $normalized['asset_group']['items'][$key]['version'] = file_exists($asset['data']) ? hash_file('xxh64', $asset['data']) : $asset['version'];
    }
    // The asset array ensures that a valid hash can only be generated via the
    // same code base. Additionally use the hash salt to ensure that hashes are