diff options
author | Sven Joachim <svenjoac@gmx.de> | 2019-11-03 00:18:19 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2019-11-26 02:42:44 +0100 |
commit | f029f28260b62a43792d39f9e935132425d4b609 (patch) | |
tree | dd163f4d60e41ced52d434690f64e93de5a213c5 | |
parent | 956272322b1a54a4fc8c539ac4000add8dfb6007 (diff) | |
download | dpkg-f029f28260b62a43792d39f9e935132425d4b609.tar.gz |
dpkg-gencontrol: Take hardlinks into account when computing Installed-Size
We should not add up the size of each hardlink into the final sum,
otherwise we will get a size in excess.
Closes: #923475
Co-Authored-by: Guillem Jover <guillem@debian.org>
Signed-off-by: Guillem Jover <guillem@debian.org>
-rw-r--r-- | debian/changelog | 3 | ||||
-rw-r--r-- | man/deb-substvars.man | 1 | ||||
-rwxr-xr-x | scripts/dpkg-gencontrol.pl | 9 |
3 files changed, 12 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog index 2fa7c28f6..88903136d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -28,6 +28,9 @@ dpkg (1.20.0) UNRELEASED; urgency=medium Reported by Julien Cristau <jcristau@debian.org>. * dpkg-query: Try to use the package synopsis from the available file if not installed. Closes: #43573 + * dpkg-gencontrol: Take into account hardlinks when computing the + Installed-Size substvar. Closes: #923475 + Patch co-authored with Sven Joachim <svenjoac@gmx.de>. * Perl modules: - Dpkg::Source::Package: Verify original tarball signatures at build time. - Dpkg::BuildFlags: Add new unset() method. diff --git a/man/deb-substvars.man b/man/deb-substvars.man index 3d5381915..bfaa6ff4f 100644 --- a/man/deb-substvars.man +++ b/man/deb-substvars.man @@ -131,6 +131,7 @@ the value of that field. If this variable is not set will compute the default value by accumulating the size of each regular file and symlink rounded to 1 KiB used units, and a baseline of 1 KiB for any other filesystem object type. +With hardlinks only being counted once as a regular file. \fBNote:\fP Take into account that this can only ever be an approximation, as the actual size used on the installed system will depend greatly on the diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 443217103..a5dda70d0 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -335,13 +335,20 @@ if ($binarypackage ne $sourcepackage || $verdiff) { if (!defined($substvars->get('Installed-Size'))) { my $installed_size = 0; + my %hardlink; my $scan_installed_size = sub { lstat or syserr(g_('cannot stat %s'), $File::Find::name); if (-f _ or -l _) { + my ($dev, $ino, $nlink) = (lstat _)[0, 1, 3]; + # For filesystem objects with actual content accumulate the size # in 1 KiB units. - $installed_size += POSIX::ceil((-s _) / 1024); + $installed_size += POSIX::ceil((-s _) / 1024) + if not exists $hardlink{"$dev:$ino"}; + + # Track hardlinks to avoid repeated additions. + $hardlink{"$dev:$ino"} = 1 if $nlink > 1; } else { # For other filesystem objects assume a minimum 1 KiB baseline, # as directories are shared resources between packages, and other |