fix: #3636834 Archive links in the archive list open a new tab instead of downloading the file

Closes https://www.drupal.org/project/earkiv/issues/3636834

Cause

The file entity of the archive was created without a MIME type, so filemime was empty in file_managed. The response for the private file had no Content-Type and no Content-Disposition header, and Chrome opened a new tab instead of saving the file.

What it does

  • New archives get the MIME type application/gzip (HTTrackCommands::ARCHIVE_MIME_TYPE) when the file entity is created.
  • The link in the File column of the archive list gets the download attribute with the file name.
  • earkiv_post_update_archive_mime_type() sets the MIME type of existing archive files (.tar.gz files referenced by an archive, without a MIME type).

Adding Content-Disposition: attachment through hook_file_download() was left out on purpose: returning headers from that hook also grants access to the file, so it would need its own access check.

Testing

On a site with existing archives:

  • drush updatedb set the MIME type of 7 archive files.
  • The private file URL now answers with Content-Type: application/gzip (it had no Content-Type before).
  • The links on /admin/content/earkiv have the download attribute.
  • phpcs (Drupal, DrupalPractice) reports no new findings compared with 1.0.x.

AI-Generated: Yes (Used Claude Code to find the cause, write the fix and write this merge request.)

Merge request reports

Loading
Loading