|
| 1 | +--- lib/fpm/package/apk.rb.original 2026-01-05 14:10:00.000000000 +0000 |
| 2 | ++++ lib/fpm/package/apk.rb 2026-01-05 14:10:00.000000000 +0000 |
| 3 | +@@ -91,6 +91,19 @@ |
| 4 | + # data tar. |
| 5 | + tar_path(staging_path(""), datatar_path) |
| 6 | + |
| 7 | ++ # Add PAX headers with file checksums |
| 8 | ++ hash_datatar(datatar_path) |
| 9 | ++ |
| 10 | ++ # Calculate datahash (SHA256 of gzipped data.tar) - required for Alpine 3.23+ |
| 11 | ++ require "zlib" |
| 12 | ++ temp_gz = datatar_path + ".gz~" |
| 13 | ++ Zlib::GzipWriter.open(temp_gz) do |gz| |
| 14 | ++ gz.mtime = 0 # Reproducible gzip |
| 15 | ++ open(datatar_path, "rb") { |f| gz.write(f.read(4096)) until f.eof? } |
| 16 | ++ end |
| 17 | ++ @datahash = calculate_file_sha256(temp_gz) |
| 18 | ++ File.unlink(temp_gz) |
| 19 | ++ |
| 20 | + # control tar. |
| 21 | + begin |
| 22 | + write_pkginfo(control_path) |
| 23 | +@@ -107,7 +120,7 @@ |
| 24 | + cut_tar_record(controltar_path) |
| 25 | + |
| 26 | + # calculate/rewrite sha1 hashes for data tar |
| 27 | +- hash_datatar(datatar_path) |
| 28 | ++ # hash_datatar(datatar_path) # Already done before datahash calculation |
| 29 | + |
| 30 | + # concatenate the two into the final apk |
| 31 | + concat_zip_tars(controltar_path, datatar_path, output_path) |
| 32 | +@@ -117,8 +130,16 @@ |
| 33 | + logger.warn("It's recommended that your package be installed with '--allow-untrusted'") |
| 34 | + end |
| 35 | + |
| 36 | ++ |
| 37 | ++ def calculate_file_sha256(file_path) |
| 38 | ++ digest = Digest::SHA256.new |
| 39 | ++ File.open(file_path, 'rb') { |f| digest.update(f.read) } |
| 40 | ++ digest.hexdigest |
| 41 | ++ end |
| 42 | ++ |
| 43 | + def write_pkginfo(base_path) |
| 44 | + |
| 45 | ++ |
| 46 | + pkginfo = "" |
| 47 | + |
| 48 | + pkginfo << "# Generated by fpm\n" |
| 49 | +@@ -129,6 +150,10 @@ |
| 50 | + pkginfo << "url = #{url()}\n" |
| 51 | + pkginfo << "size = 102400\n" # totally magic, not sure what it's used for. |
| 52 | + |
| 53 | ++ |
| 54 | ++ if @datahash |
| 55 | ++ pkginfo << "datahash = #{@datahash}\n" |
| 56 | ++ end |
| 57 | + # write depends lines |
| 58 | + for dependency in dependencies() |
| 59 | + pkginfo << "depend = #{dependency}\n" |
| 60 | +@@ -300,6 +325,7 @@ |
| 61 | + |
| 62 | + # zip each path separately |
| 63 | + Zlib::GzipWriter.open(temp_apath) do |target_writer| |
| 64 | ++ target_writer.mtime = 0 # Reproducible gzip |
| 65 | + open(apath, "rb") do |file| |
| 66 | + until(file.eof?()) |
| 67 | + target_writer.write(file.read(4096)) |
| 68 | +@@ -308,6 +334,7 @@ |
| 69 | + end |
| 70 | + |
| 71 | + Zlib::GzipWriter.open(temp_bpath) do |target_writer| |
| 72 | ++ target_writer.mtime = 0 # Reproducible gzip |
| 73 | + open(bpath, "rb") do |file| |
| 74 | + until(file.eof?()) |
| 75 | + target_writer.write(file.read(4096)) |
0 commit comments