diff options
author | Guillem Jover <guillem@debian.org> | 2015-01-20 02:37:20 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2015-01-28 20:50:33 +0100 |
commit | 9ed7d4d47b73ffe67e1f7d31f899a1dfd43d490b (patch) | |
tree | 747bd6e51dfd16b04d7a1efc1bb6b5667cd1c9ad /scripts/dpkg-gencontrol.pl | |
parent | d5bbe517c05e6e3712636726a1bcf7b22c3fd17b (diff) | |
download | dpkg-9ed7d4d47b73ffe67e1f7d31f899a1dfd43d490b.tar.gz |
dpkg-gencontrol: Rework Installed-Size field default value computation
Switch from «du» to File::Find, and accumulate size usage per filesystem
object, on 1 KiB units. Use the actual size only for regular files and
symlinks, and just 1 KiB for any other filesystem object type.
This guarantees a constant and reproducible size regardless of the
build system filesystem being used.
Document how the value is computed, and that it is just a size
approximation.
Closes: #650077
Diffstat (limited to 'scripts/dpkg-gencontrol.pl')
-rwxr-xr-x | scripts/dpkg-gencontrol.pl | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 09a695615..6b076f4c6 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -4,7 +4,7 @@ # # Copyright © 1996 Ian Jackson # Copyright © 2000,2002 Wichert Akkerman -# Copyright © 2006-2014 Guillem Jover <guillem@debian.org> +# Copyright © 2006-2015 Guillem Jover <guillem@debian.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ use strict; use warnings; use POSIX qw(:errno_h :fcntl_h); +use File::Find; + use Dpkg (); use Dpkg::Gettext; use Dpkg::ErrorHandling; @@ -334,26 +336,25 @@ if ($oppackage ne $sourcepackage || $verdiff) { } if (!defined($substvars->get('Installed-Size'))) { - my $c = open(my $du_fh, '-|'); - if (not defined $c) { - syserr(g_('cannot fork for %s'), 'du'); - } - if (!$c) { - chdir("$packagebuilddir") - or syserr(g_("chdir for du to \`%s'"), $packagebuilddir); - exec('du', '-k', '-s', '--apparent-size', '.') - or syserr(g_('unable to execute %s'), 'du'); - } - my $duo = ''; - while (<$du_fh>) { - $duo .= $_; - } - close($du_fh); - subprocerr(g_("du in \`%s'"), $packagebuilddir) if $?; - if ($duo !~ m/^(\d+)\s+\.$/) { - error(g_("du gave unexpected output \`%s'"), $duo); - } - $substvars->set_as_auto('Installed-Size', $1); + my $installed_size = 0; + my $scan_installed_size = sub { + lstat or syserr(g_('cannot stat %s'), $File::Find::name); + + if (-f _ or -l _) { + # For filesystem objects with actual content accumulate the size + # in 1 KiB units. + $installed_size += POSIX::ceil((-s _) / 1024); + } else { + # For other filesystem objects assume a minimum 1 KiB baseline, + # as directories are shared resources between packages, and other + # object types are mainly metadata-only, supposedly consuming + # at most an inode. + $installed_size += 1; + } + }; + find($scan_installed_size, $packagebuilddir); + + $substvars->set_as_auto('Installed-Size', $installed_size); } if (defined($substvars->get('Extra-Size'))) { my $size = $substvars->get('Extra-Size') + $substvars->get('Installed-Size'); |