diff options
Diffstat (limited to 'lib/MGA/DrakISO/BuildLoop.pm')
-rw-r--r-- | lib/MGA/DrakISO/BuildLoop.pm | 75 |
1 files changed, 30 insertions, 45 deletions
diff --git a/lib/MGA/DrakISO/BuildLoop.pm b/lib/MGA/DrakISO/BuildLoop.pm index 8a83e03..ebaef11 100644 --- a/lib/MGA/DrakISO/BuildLoop.pm +++ b/lib/MGA/DrakISO/BuildLoop.pm @@ -19,8 +19,8 @@ # SYNOPSIS # -------- -# This package provides a function to build the compressed images that will -# be mounted as loopback filesystems when booting a Live system. +# This package provides a function to build the compressed image that will +# be mounted as a loopback filesystem when booting a Live system. package MGA::DrakISO::BuildLoop; @@ -31,17 +31,16 @@ use MDK::Common; use File::Temp qw(tmpnam); use MGA::DrakISO::LiveBuild; -use MGA::DrakISO::Loopback; use MGA::DrakISO::Utils; use Exporter; our @ISA = qw(Exporter); -our @EXPORT = qw(build_live_loopback_files list_loopback_modules); +our @EXPORT = qw(build_live_loopback_file); -# This is the top-level function called to build the loopback images. The Live +# This is the top-level function called to build the loopback image. The Live # root filesystem must have been prepared before calling this function. # -sub build_live_loopback_files { +sub build_live_loopback_file { my ($build) = @_; my $root = $build->get_live_root; @@ -49,22 +48,32 @@ sub build_live_loopback_files { # make sure no external filesystems are mounted before creating the loopback umount_all_in_root($root); + my $total = directory_usage($root); + print "Have to process " . int($total/1000000) . " MB\n" if $::verbose; + + my $dest = $build->get_build_dir('loopbacks') . '/distrib.sqfs'; + mkdir_p(dirname($dest)); + + my $exclude_list = tmpnam(); my @excluded_files = expand_file_list($build, @{$build->{loopbacks}{exclude} || []}); - my @modules_files = expand_file_list($build, @{$build->{loopbacks}{modules} || []}); - - foreach (grep { exists $loop_types{$_->{type}}{build} } @{$build->{mount}{dirs} || []}) { - local $_->{exclude} = [ @excluded_files, @modules_files ]; - $loop_types{$_->{type}}{build}->($build, $_); - } - - foreach my $module (list_loopback_modules($build)) { - my $copy_tree = $root . "/tmp/draklive/loop/$module->{name}"; - run_as_root('rm', '-rf', $copy_tree); - hardlink_filtered($root, $copy_tree, $module->{files}); - my $loop = $loop_types{$module->{type}}; - $loop->{build}->($build, { path => "/modules/$module->{name}", root => $copy_tree, exclude => \@excluded_files }); - run_as_root('rm', '-rf', $copy_tree); - } + output_p($exclude_list, map { $root . "$_\n" } grep { run_as_root('test', '-e', $root . $_) } @excluded_files); + + my $sort = $build->{settings}{config_root} . '/config/distrib.sort'; + run_as_root(join(' ', + 'mksquashfs', + $root, $dest, + '-noappend', + '-comp', 'xz', + '-b', '1048576', + '-ef', $exclude_list, + if_(-f $sort, '-sort', $sort), + if_($::verbose > 2, '-info', '-progress'), + if_($::verbose < 2, '-no-progress'), + # due to lack of a -quiet option + if_($::verbose < 2, '> /dev/null'), + )) or die "ERROR: unable to run mksquashfs\n"; + + unlink $exclude_list; } sub expand_file_list { @@ -76,28 +85,4 @@ sub expand_file_list { } @files; } -#- hardlink recursively file list to a directory -sub hardlink_filtered { - my ($src, $dest, $files) = @_; - mkdir_p($dest); - my $list_file = tmpnam(); - output_p($list_file, map { "$_\n" } grep { -e $src . $_ } @$files); - #- cpio -pldm won't copy recursively, use rsync -r instead - run_as_root('rsync', '-ar', '--files-from=' . $list_file, '--link-dest=' . $src, $src, $dest); - unlink $list_file; -} - -sub list_loopback_modules { - my ($build) = @_; - map { - my $l = $_; - map { - my $list = $_; - my $name = basename($list); - $name =~ s/\.[^.]+$//; - { type => $l->{type}, name => $name, files => [ expand_file_list($build, { source => $list }) ] }; - } glob(($_->{rooted} && $build->get_live_root) . $_->{source}); - } @{$build->{loopbacks}{modules}}; -} - 1; |