c71347f0b7
OBS-URL: https://build.opensuse.org/package/show/Kernel:stable/kernel-source?expand=0&rev=1682
32 lines
564 B
Perl
32 lines
564 B
Perl
#!/usr/bin/perl
|
|
use strict;
|
|
use warnings;
|
|
|
|
$/="";
|
|
while (<>) {
|
|
chomp;
|
|
|
|
my %dups; # hash: inode -> array of filenames
|
|
foreach (split /\n/) {
|
|
my $inode = (stat)[1];
|
|
push @{$dups{$inode}}, $_;
|
|
}
|
|
|
|
my @keys = keys(%dups);
|
|
|
|
# all are hardlinks to the same data
|
|
next if (scalar @keys < 2);
|
|
|
|
# sort by nlink
|
|
@keys = sort { scalar $dups{$a} <=> scalar $dups{$b} } @keys;
|
|
my $target = $dups{shift @keys}[0];
|
|
|
|
foreach (@keys) {
|
|
foreach (@{$dups{$_}}) {
|
|
print "relinking $_ -> $target\n";
|
|
unlink($_);
|
|
link($target, $_) or die "link failed";
|
|
}
|
|
}
|
|
}
|