forked from josch/mmdebstrap
Take hard links into account when computing disk usage based on dpkg-gencontrol.pl
Thanks: Guillem Jover <guillem@debian.org>, Sven Joachim <svenjoac@gmx.de>
This commit is contained in:
parent
a7586e55d1
commit
35cd477fea
1 changed files with 14 additions and 6 deletions
20
mmdebstrap
20
mmdebstrap
|
@ -4393,19 +4393,27 @@ sub approx_disk_usage {
|
||||||
# We ignore /dev because depending on the mode, the directory might be
|
# We ignore /dev because depending on the mode, the directory might be
|
||||||
# populated or not and we want consistent disk usage results independent
|
# populated or not and we want consistent disk usage results independent
|
||||||
# of the mode.
|
# of the mode.
|
||||||
my $installed_size = 0;
|
my $installed_size = 0;
|
||||||
|
my %hardlink;
|
||||||
my $scan_installed_size = sub {
|
my $scan_installed_size = sub {
|
||||||
if ($File::Find::name eq "$directory/dev") {
|
if ($File::Find::name eq "$directory/dev") {
|
||||||
# add all entries of @devfiles once
|
# add all entries of @devfiles once
|
||||||
$installed_size += scalar @devfiles;
|
$installed_size += scalar @devfiles;
|
||||||
|
return;
|
||||||
} elsif ($File::Find::name =~ /^$directory\/dev\//) {
|
} elsif ($File::Find::name =~ /^$directory\/dev\//) {
|
||||||
# ignore everything below /dev
|
# ignore everything below /dev
|
||||||
} elsif (-l $File::Find::name) {
|
return;
|
||||||
# -f follows symlinks, so we first check if we have a symlink
|
}
|
||||||
$installed_size += 1;
|
|
||||||
} elsif (-f $File::Find::name) {
|
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
|
# 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 {
|
} else {
|
||||||
# all other entries are assumed to only take up one block
|
# all other entries are assumed to only take up one block
|
||||||
$installed_size += 1;
|
$installed_size += 1;
|
||||||
|
|
Loading…
Reference in a new issue