This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=f029f28260b62a43792d39f9e935132425d4b609

commit f029f28260b62a43792d39f9e935132425d4b609
Author: Sven Joachim <[email protected]>
AuthorDate: Sun Nov 3 00:18:19 2019 +0100

    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 <[email protected]>
    Signed-off-by: Guillem Jover <[email protected]>
---
 debian/changelog           | 3 +++
 man/deb-substvars.man      | 1 +
 scripts/dpkg-gencontrol.pl | 9 ++++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

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 <[email protected]>.
   * 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 <[email protected]>.
   * 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

-- 
Dpkg.Org's dpkg

Reply via email to