Skip to content

Commit

Permalink
make times in iso images reproducible
Browse files Browse the repository at this point in the history
by replacing mkisofs with xorriso, which enables reproducible mode when
environment variable SOURCE_DATE_EPOCH is set.
  • Loading branch information
JanZerebecki committed Jul 28, 2023
1 parent a15501e commit 020998d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
64 changes: 47 additions & 17 deletions modules/KIWIIsoLinux.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use Carp qw /cluck/;
use Fcntl;
use File::Find;
use File::Basename;
use POSIX qw(strftime);

#==========================================
# Base class
Expand Down Expand Up @@ -105,8 +106,13 @@ sub new {
$tool = $genTool;
$tool_type = "genisoimage";
} else {
my $mkTool = $locator -> getExecPath('mkisofs');
my $mkTool = $locator -> getExecPath('xorrisofs');
if ($mkTool && -x $mkTool) {
$tool = $mkTool;
# xorrisofs is a drop in replacement
$tool_type = "mkisofs";
} elsif ($mkTool && -x $mkTool) {
$mkTool = $locator -> getExecPath('mkisofs');
$tool = $mkTool;
$tool_type = "mkisofs";
} else {
Expand Down Expand Up @@ -1021,6 +1027,15 @@ sub createISO {
}
}
#==========================================
# Ensure xorrisofs which stands in for mkisofs produces reproducible output
#------------------------------------------
if(!$ENV{SOURCE_DATE_EPOCH}) {
$kiwi->warning("[W] Failed to read environment variable SOURCE_DATE_EPOCH, setting to 0.");
$ENV{SOURCE_DATE_EPOCH} = "0";
}
my $date = strftime("%Y%m%d%H%M%S", gmtime($ENV{SOURCE_DATE_EPOCH}));
$para = "$para --set_all_file_dates $date";
#==========================================
# Call mkisofs first stage
#------------------------------------------
# log sort file
Expand Down Expand Up @@ -1110,32 +1125,47 @@ sub isols {
my $iso = $this -> {dest};
my $fd = FileHandle -> new();
my $dir = "/";
my $isoinfo_opts = " -R -l -i $iso 2>/dev/null |";
my $opts = " -indev $iso -find / -not -type d -exec report_lba 2>/dev/null |";
my $files;
local $_;
my $isoinfo_cmd = "/usr/bin/isoinfo";
if (! -x $isoinfo_cmd){
$isoinfo_cmd = "/usr/lib/genisoimage/isoinfo";
if (! -x $isoinfo_cmd){
return;
my $cmd = "/usr/bin/xorriso";
if (! -x $cmd){
$cmd = "/usr/bin/isoinfo";
$opts = " -R -l -i $iso 2>/dev/null |";
if (! -x $cmd){
$cmd = "/usr/lib/genisoimage/isoinfo";
if (! -x $cmd){
return;
}
}
}
if (! $fd -> open ($isoinfo_cmd . $isoinfo_opts)) {
if (! $fd -> open ($cmd . $opts)) {
return;
}
while(<$fd>) {
if(/^Directory listing of\s*(\/.*\/)/) {
$dir = $1;
next;
}
if(/.*(-)[-rxw]{9}.*\s\[\s*(\d+)(\s+\d+)?\]\s+(.*?)\s*$/) {
my $type = $1;
$type = ' ' if $type eq '-';
if($4 ne '.' && $4 ne '..') {
if($cmd eq "/usr/bin/xorriso") {
if(/Report layout:\s+xt\s,\s+Startlba\s,\s+Blocks\s,\s+Filesize\s,\s+ISO image path$/) {
next;
}
if(/File data lba:\s+(\d+)\s,\s+(\d+)\s,\s+(\d+)\s,\s+(\d+)\s,\s+'(\/.*)'$/) {
push @$files, {
name => "$dir$4",type => $type,start => $2 + 0
name => $5, type => ' ', start => $2
};
}
} else {
if(/^Directory listing of\s*(\/.*\/)/) {
$dir = $1;
next;
}
if(/.*(-)[-rxw]{9}.*\s\[\s*(\d+)(\s+\d+)?\]\s+(.*?)\s*$/) {
my $type = $1;
$type = ' ' if $type eq '-';
if($4 ne '.' && $4 ne '..') {
push @$files, {
name => "$dir$4",type => $type,start => $2 + 0
};
}
}
}
}
$fd -> close();
Expand Down
2 changes: 1 addition & 1 deletion rpm/product-builder.spec
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Requires: obs-build
%endif
Requires: checkmedia
Requires: inst-source-utils
Requires: mkisofs
Requires: xorriso
Requires: product-builder-plugin
%ifarch %ix86 x86_64
Requires: syslinux
Expand Down

0 comments on commit 020998d

Please sign in to comment.