+ my $df = df($iso_dir)->{bavail} || die "can't get free space on $iso_dir";
+ $df *= 1024; # calulate space in bytes
+ if ($df < $v_size) {
+ warn "ABORTED: not enough disk space to create ISO ! [need ", fmt_mb($v_size), " have ", fmt_mb( $df ), " on $iso_dir]\n";
+ next;
+ }
+
+ my $volumes = $#volumes + 1;
+ my $volume_nr = 1;
+
+ foreach my $v (@volumes) {
+
+ #print Dumper($v);
+
+ my $iso_size = 0;
+ my $disk_name = $dvd_nr;
+ # suffix added to multi-volume archives
+ my $volume_suffix = '';
+
+ if ($volumes > 1) {
+ $volume_suffix = '_' . $volume_nr;
+ $disk_name .= ' ' . $volume_nr . '/' . $volumes;
+ }
+
+ print "Processing DVD #$dvd_nr, volume $volume_nr/$volumes [", fmt_mb($v->{size}), "]\n";
+
+ my $iso_file = my $xml_file = my $stage =
+ "${iso_dir}/${dvd_nr}";
+
+ $iso_file .= $volume_suffix . '.iso';
+ $xml_file .= '.xml';
+
+ $stage .= $volume_suffix . '.stage';
+
+ my $md5_file = "${stage}/${dvd_nr}${volume_suffix}.md5";
+
+ #
+ # check if ISO file exists
+ #
+
+ if (! -e $iso_file) {
+
+ # create stage directory
+ if (-e $stage) {
+ rmtree($stage) || die "can't remove $stage: $!";
+ }
+ mkpath($stage);
+
+ # open file for md5sums
+ open(my $md5, "> $md5_file") || skip "can't open $md5_file: $!";
+
+ my $parts_on_this_volume = 0;
+
+ foreach my $p (@{ $v->{parts} }) {
+ my $tar_file = $p->{filename} || die "no filename in part", Dumper($p);
+ my $rel_path = $tar_file;
+
+ if (-d "$tar_dir/$rel_path") {
+ mkpath("$stage/$rel_path") unless (-d "$stage/$rel_path");
+ $rel_path .= '/' . $p->{part_nr};
+ }
+ $rel_path .= '.tar.gz';
+
+ skip "can't find increment $rel_path: $!" unless (-r "$tar_dir/$rel_path");
+
+ add_symlink("$tar_dir/$rel_path", "$stage/$rel_path");
+
+ my $md5sum = $p->{md5} || die "no md5 in part ", Dumper($p);
+ chomp($md5sum);
+ print $md5 "$md5sum $rel_path\n" || die "can't write md5sum: $!";