Commit 4febcc23 authored by mark burdett's avatar mark burdett
Browse files

Issue #3088056 by beeyayjay, mfb: Add option to only create hashes for local files

parent 03825b94
Loading
Loading
Loading
Loading
+6 −0
Changes for filehash.admin.inc: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,6 +16,12 @@ function filehash_settings() {
    '#title' => t('Enabled hash algorithms'),
    '#type' => 'checkboxes',
  );
  $form['filehash_local_only'] = array(
    '#default_value' => variable_get('filehash_local_only', FALSE),
    '#description' => t('If checked, file hashes will be generated only for files using local stream wrappers (public, temporary, etc.).'),
    '#title' => t('Hash local files only'),
    '#type' => 'checkbox',
  );
  $form['filehash_dedupe'] = array(
    '#default_value' => variable_get('filehash_dedupe', 0),
    '#description' => t('If checked, prevent duplicate uploaded files from being saved. Note, enabling this setting has privacy implications, as it allows users to determine if a particular file has been uploaded to the site.'),
+1 −0
Changes for filehash.install: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ function filehash_schema() {
function filehash_uninstall() {
  variable_del('filehash_algos');
  variable_del('filehash_dedupe');
  variable_del('filehash_local_only');
}

/**
+6 −0
Changes for filehash.module: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -116,6 +116,12 @@ function filehash_file_update($file) {
 * Wraps hash_file() to also support BLAKE2b.
 */
function filehash_hash($algo, $uri) {
  if (variable_get('filehash_local_only', FALSE)) {
    $local = file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL);
    if (!isset($local[file_uri_scheme($uri)])) {
      return FALSE;
    }
  }
  // If a file's directory was deleted, the stream wrapper will generate an
  // empty path. Opening a file with empty path throws a ValueError on PHP 8.
  try {