Package : apt-mirror
Version : 0.5.4-2
Distro : Devuan Excalibur (not yet released), based on Debian Trixie. I confirmed that the Excalibur apt-mirror script is unchanged from Debian Trixie.

**** MSG FOR THE MAINTAINER ****

Hi Maintainer:

I ran into the same error "Use of uninitialized value $lines{"Files:"}". The problem is in the subroutine "process_index". This subroutine parses two different text files: "Packages" (found in the binary packages), and "Sources" (found in the source code packages). Although the parsing logic for the Packages file has been updated so that the md5sum is an optional field, the parsing logic for the Sources file (found in the source code packages) has NOT been updated. So it assumes that every package must contain the "Files:" section containing md5sums.

This means that the error occurs only if you're mirroring the source code (using deb-src).

I reproduced this problem with a Devuan repository and a Debian repository:

  - Devuan test, mirror.list

deb-src http://deb.devuan.org/merged daedalus-security main

This downloads the file from: http://deb.devuan.org/merged/dists/daedalus-security/main/source/Sources.gz

  - Debian test, mirror.list

deb-src http://deb.devuan.org/merged daedalus-security main

This downloads the file from: http://deb.debian.org/debian/dists/bookworm-updates/main/source/Sources.xz

If you look open the Sources file in each test, you'll see that neither of their package descriptions contain "Files:" (md5sums), nor "Checksums-Sha1", only "Checksums-Sha256".

* A Solution

My solution is to rewrite the entire else block to handle any combination of the presence/absence of the 3 section names: "Files:", "Checksums-Sha1:", "Checksums-Sha256:":

  else
  {    # Sources index

#The sections "Files:", "Checksums-Sha1:", and "Checksums-Sha256" contain 1 or more lines with 3 #space-separated fields: md5/sha1/sha256 checksum, file size in bytes, file name #There's no guarantee that all 3 sections will be defined, or that they will have the same list of files. #Use a hash to keep track of the file names and their sizes. Then update the ALL and NEW files afterwards.
      my %package_files;
      my %sections = (
          "Files:"            => *FILES_MD5   ,
          "Checksums-Sha1:"   => *FILES_SHA1  ,
          "Checksums-Sha256:" => *FILES_SHA256,
      );

      foreach my $section_name (keys %sections)
      {
          if (!defined($lines{$section_name})) { next; }

          foreach ( split( /\n/, $lines{$section_name} ) )
          {
              next if $_ eq '';
              my @file = split;
              die("apt-mirror: invalid Sources format") if @file != 3;
print { $sections{$section_name} } $file[0] . " " . remove_double_slashes( $path . "/" . $lines{"Directory:"} . "/" . $file[2] ) . "\n";
              $package_files{$file[2]} = $file[1];
          }
      }

      my $file_size_bytes;
      my $file_path;
      foreach my $file_name (keys %package_files)
      {
          $file_size_bytes = $package_files{$file_name};
$file_path = remove_double_slashes( $path . "/" . $lines{"Directory:"} . "/" . $file_name );

          $skipclean{ $file_path } = 1;
          print FILES_ALL $file_path . "\n";

if ( need_update( $mirror . "/" . $lines{"Directory:"} . "/" . $file_name, $file_size_bytes ) )
          {
print FILES_NEW remove_double_slashes( $uri . "/" . $lines{"Directory:"} . "/" . $file_name ) . "\n"; add_url_to_download( $uri . "/" . $lines{"Directory:"} . "/" . $file_name, $file_size_bytes );
          }
      }
  }

I tested this solution with the 2 deb-src URLs mentioned above, and this code runs without errors and correctly appends the SHA256 sums to the file "SHA256", since that's the section defined in those two repositories.

**** MSG FOR READERS AT bugs.debian.org ****

If you're reading this on bugs.debian.org, and you want to try my fix, you can make a copy of the script and try the changes. That way, if anything goes wrong, the original apt-mirror script is still available.

- Copy the apt-mirror script into another directory, such as /opt, which is usually empty. - In a text editor, search for the string "sub process_index". This the beginning of the "process_index" subroutine. - Within this subroutine, look for the "else" block of code with the comment "# Sources index". This block of code parses the "Sources" file.
  - Replace the entire "else" block with the code mentioned above.
  - To run the updated apt-mirror:

/opt/apt-mirror <your apt-mirror config file>

  - To run the originally installed apt-mirror script:

apt-mirror <your apt-mirror config file>

Reply via email to