Compare commits

..

8 commits

5 changed files with 73 additions and 22 deletions

View file

@ -1,3 +1,8 @@
1.4.3 (2024-02-01)
------------------
- take hard links into account when computing disk usage
1.4.2 (2024-01-29)
------------------

View file

@ -365,11 +365,11 @@ Variants: custom
Modes: chrootless
Needs-APT-Config: true
Test: install-libmagic-mgc-on-arm64
Test: install-libmagic-mgc-on-foreign
Variants: custom
Modes: chrootless
Skip-If:
hostarch != "amd64"
hostarch not in ["amd64", "arm64"]
not have_binfmt
Test: install-busybox-based-sub-essential-system
@ -380,6 +380,7 @@ Modes: root unshare fakechroot
Skip-If:
hostarch not in ["amd64", "arm64"]
mode == "fakechroot" and not run_ma_same_tests
mode == "fakechroot" and hostarch == "arm64" # usrmerge postinst under fakechroot wants to copy /lib/ld-linux-x86-64.so.2 (which does not exist) instead of /lib64/ld-linux-x86-64.so.2
not have_binfmt
Test: no-sbin-in-path

View file

@ -23,7 +23,7 @@
use strict;
use warnings;
our $VERSION = '1.4.2';
our $VERSION = '1.4.3';
use English;
use Getopt::Long;
@ -1551,34 +1551,41 @@ sub setup_mounts {
if (any { $_ eq 'chroot/start-stop-daemon' } @{ $options->{skip} }) {
info "skipping chroot/start-stop-daemon as requested";
} else {
# $options->{root} must not be part of $ssdloc but must instead be
# evaluated at the time the cleanup is run or otherwise, when
# performing a pivot-root, the ssd location will still be prefixed
# with the chroot path even though we changed root
my $ssdloc;
if (-f "$options->{root}/sbin/start-stop-daemon") {
$ssdloc = "$options->{root}/sbin/start-stop-daemon";
$ssdloc = "/sbin/start-stop-daemon";
} elsif (-f "$options->{root}/usr/sbin/start-stop-daemon") {
$ssdloc = "$options->{root}/usr/sbin/start-stop-daemon";
$ssdloc = "/usr/sbin/start-stop-daemon";
}
push @cleanup_tasks, sub {
return unless length $ssdloc;
if (-e "$ssdloc.REAL") {
move("$ssdloc.REAL", "$ssdloc")
or error "cannot move start-stop-daemon: $!";
warning "/sbin/start-stop-daemon fake replaced with real";
if (-e "$options->{root}/$ssdloc.REAL") {
move(
"$options->{root}/$ssdloc.REAL",
"$options->{root}/$ssdloc"
) or error "cannot move start-stop-daemon: $!";
}
};
if (length $ssdloc) {
if (-e "$ssdloc.REAL") {
error "$ssdloc.REAL already exists";
if (-e "$options->{root}/$ssdloc.REAL") {
error "$options->{root}/$ssdloc.REAL already exists";
}
move("$ssdloc", "$ssdloc.REAL")
or error "cannot move start-stop-daemon: $!";
open my $fh, '>', $ssdloc
move(
"$options->{root}/$ssdloc",
"$options->{root}/$ssdloc.REAL"
) or error "cannot move start-stop-daemon: $!";
open my $fh, '>', "$options->{root}/$ssdloc"
or error "cannot open start-stop-daemon: $!";
print $fh "#!/bin/sh\n";
print $fh
"echo \"Warning: Fake start-stop-daemon called, doing"
. " nothing\">&2\n";
close $fh;
chmod 0755, "$ssdloc"
chmod 0755, "$options->{root}/$ssdloc"
or error "cannot chmod start-stop-daemon: $!";
}
}
@ -4387,18 +4394,26 @@ sub approx_disk_usage {
# populated or not and we want consistent disk usage results independent
# of the mode.
my $installed_size = 0;
my %hardlink;
my $scan_installed_size = sub {
if ($File::Find::name eq "$directory/dev") {
# add all entries of @devfiles once
$installed_size += scalar @devfiles;
return;
} elsif ($File::Find::name =~ /^$directory\/dev\//) {
# ignore everything below /dev
} elsif (-l $File::Find::name) {
# -f follows symlinks, so we first check if we have a symlink
$installed_size += 1;
} elsif (-f $File::Find::name) {
return;
}
lstat or error "cannot stat $File::Find::name";
if (-f _ or -l _) {
my ($dev, $ino, $nlink) = (lstat _)[0, 1, 3];
return if exists $hardlink{"$dev:$ino"};
# Track hardlinks to avoid repeated additions.
$hardlink{"$dev:$ino"} = 1 if $nlink > 1;
# add file size in 1024 byte blocks, rounded up
$installed_size += int(((-s $File::Find::name) + 1024) / 1024);
$installed_size += int(((-s _) + 1024) / 1024);
} else {
# all other entries are assumed to only take up one block
$installed_size += 1;
@ -5212,6 +5227,12 @@ sub main() {
}
}
if (defined $options->{qemu} && $options->{mode} eq 'fakechroot') {
if (!can_execute 'dpkg-architecture') {
error "cannot find dpkg-architecture";
}
}
{
$options->{suite} = undef;
if (scalar @ARGV > 0) {

View file

@ -298,6 +298,16 @@ WORKDIR=$(mktemp -d)
FAT_OFFSET_SECTORS=$((1024*2))
FAT_SIZE_SECTORS=$((1024*254))
# The image is raw and not in qcow2 format because:
# - faster run-time as the "qemu-image convert" step is not needed
# - image can be used independent of qemu tooling
# - modifying the image just with "mount" instead of requiring qemu-nbd
# - sparse images make the file just as small as with qcow2
# - trim support is more difficult on qcow2
# - snapshots and overlays work just as well with raw images
# - users who prefer qcow2 get to choose to run it themselves with their own
# custom options like compression
#
# Make the image writeable to the first subgid. mmdebstrap will map this gid to
# the root group. unshare instead will map the current gid to 0 and the first
# subgid to 1. Therefore mmdebstrap will be able to write to the image.

View file

@ -17,13 +17,27 @@ if [ "$(id -u)" -eq 0 ] && [ "{{ MODE }}" != "root" ] && [ "{{ MODE }}" != "auto
prefix="runuser -u ${SUDO_USER:-user} --"
fi
$prefix {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} --architectures=arm64 --include=libmagic-mgc {{ DIST }} /tmp/debian-chroot {{ MIRROR }}
case "$(dpkg --print-architecture)" in
arm64)
foreign_arch=amd64
;;
amd64)
foreign_arch=arm64
;;
*)
echo "unsupported native architecture" >&2
exit 1
;;
esac
$prefix {{ CMD }} --mode={{ MODE }} --variant={{ VARIANT }} --architectures="$foreign_arch" --include=libmagic-mgc {{ DIST }} /tmp/debian-chroot {{ MIRROR }}
# delete contents of libmagic-mgc
rm /tmp/debian-chroot/usr/lib/file/magic.mgc
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/README.Debian
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/changelog.Debian.gz
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/changelog.gz
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/copyright
rm /tmp/debian-chroot/usr/share/doc/libmagic-mgc/"changelog.Debian.$foreign_arch.gz"
rm /tmp/debian-chroot/usr/share/file/magic.mgc
rm /tmp/debian-chroot/usr/share/misc/magic.mgc
# delete real files