Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Anyone have an efficient method of removing .la files?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
dopey
Apprentice
Apprentice


Joined: 10 Feb 2003
Posts: 235

PostPosted: Mon Jun 12, 2006 2:55 pm    Post subject: Anyone have an efficient method of removing .la files? Reply with quote

I've noticed that more often than not, an unmerge of a package doesn't clean up the .la files. In the past I sorta paid attention to the unmerge, and removed any modified files that made sense to manually, but since it's a manual method, it's not really scalable, and I've missed files here and there.

The new revdep-rebuild in gentoolkit-2.2 seems to look for libtool files that have incorrect library dependencies. Problem is, it's repeatedly finding .la files now that don't exist in a package (because I've unmerged the package). I've just been deleting these manually after running a couple of runs of revdep-rebuild.

The other solution I have is a script that finds all .la files and individually checks if they are owned by a package. None of these methods are really very scalable.

Any better ideas?
Back to top
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Mon Jun 12, 2006 6:06 pm    Post subject: Reply with quote

Here you go. With a little more time, you could automatically delete the la files that don't belong to anything.

find / -name *.la -printf %p"\t" -exec equery -qe belongs {} \;

Any .la file that does not belong to anything will not have a package printed next to it.
Back to top
View user's profile Send private message
dopey
Apprentice
Apprentice


Joined: 10 Feb 2003
Posts: 235

PostPosted: Mon Jun 12, 2006 8:25 pm    Post subject: Reply with quote

Right, but my point is, that's just horribly ugly, since aren't you basically running an equery for every *.la file found?

Of course, I'm just hoping there's a better solution, but in reality, there probably isn't one.
Back to top
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Mon Jun 12, 2006 9:14 pm    Post subject: Reply with quote

Without creating a list of .la files in the installed pacakages, it will "be ugly".

Here's an alternative to the equery command.

find / -name *.la -printf %p"\t" -exec grep {} /var/db/pkg/*/*/CONTENTS \;
Back to top
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Mon Jun 12, 2006 9:44 pm    Post subject: Reply with quote

Or, like I posted above, just create a list of all .la files in all installed packages, then run search against that.

The following perl one liner might not be pretty, but it works!

perl -lane '$pk=(join"/",(split"/", $ARGV)[-3,-2]); print "$pk $F[1]" if $F[1] =~ /\.la$/' /var/db/pkg/*/*/CONTENTS > all-la.txt

Then just:

find / -name *.la -printf %p"\t" -exec grep -c {} all-la.txt \;
Back to top
View user's profile Send private message
dopey
Apprentice
Apprentice


Joined: 10 Feb 2003
Posts: 235

PostPosted: Mon Jun 12, 2006 10:24 pm    Post subject: Reply with quote

Let me ask my question in a slightly different way :)

Pardon my ignorance regarding libtool, but would it be safe to say, if a libtool (.la) file exists, and no .so file exists for the same basename, that it's an invalid file right?

I guess I was thinking along that lines rather than reading up files, and then searching through a "database" to see if the file belongs to something.
Back to top
View user's profile Send private message
Gergan Penkov
Veteran
Veteran


Joined: 17 Jul 2004
Posts: 1464
Location: das kleinste Kuhdorf Deutschlands :)

PostPosted: Mon Jun 12, 2006 10:33 pm    Post subject: Reply with quote

well look here https://bugs.gentoo.org/show_bug.cgi?id=90744#c8
although not what you really want, depending on what you use (gnome) it could be a safe operation to remove all of the la-s, as they are not used for anything usefull, my system is totally la-free for a three months or so and is working just fine, aside from the need to patch 3-4 packages.
_________________
"I knew when an angel whispered into my ear,
You gotta get him away, yeah
Hey little bitch!
Be glad you finally walked away or you may have not lived another day."
Godsmack
Back to top
View user's profile Send private message
msalerno
Veteran
Veteran


Joined: 17 Dec 2002
Posts: 1338
Location: Sweating in South Florida

PostPosted: Tue Jun 13, 2006 11:31 am    Post subject: Reply with quote

I had a very very slow day at work...

This will create a hash of all of the .la files from the installed packages, search the filesystem, look for the package that the .la file belongs to and print any orphans.

Code:
#! /usr/bin/perl -w
use strict;
use File::Find ();

my %installedla;
my $portagedb = "/var/db/pkg";
my $runningsize;

print "Getting list of all .la files from installed packages\n";
opendir(PORTAGEDB, $portagedb) || die "Cannot open dir $portagedb\n";
my @categories = grep { -d "$portagedb/$_" && !/^\.{1,2}$/ } readdir(PORTAGEDB);
close PORTAGEDB;
foreach my $cat (@categories){
        opendir(PACKAGES, "$portagedb/$cat") || die "Cannot open dir $portagedb\/$_\n";
        my @packages = grep { -d "$portagedb/$cat/$_" && !/^\.{1,2}$/ } readdir(PACKAGES);
        close PACKAGES;
        foreach (@packages){
                open(CONTENTS, "< $portagedb/$cat/$_/CONTENTS") || die "Cannot open $portagedb/$cat/$_/CONTENTS $!\n";
                while(<CONTENTS>){
                        if ( (split " ", $_)[1] =~ /\.la\z$/ ){
                                my $contentscontents = (split " ", $_)[1];
                                next if !$contentscontents;
                                $installedla{$contentscontents} = $cat if !exists $installedla{$contentscontents};
                        }
                }
                close CONTENTS;
        }
}

print "List complete\nSearching filesystem for orphaned .la files\n";
File::Find::find({wanted => \&fslas}, '/');
print "Finished\nYou could save yourself a whopping ".KB($runningsize)." !\n";

exit;

sub fslas {
        if ( $_ =~ /\.la\z$/ && (-f $File::Find::name) ){
                my $size = -s $File::Find::name;
                if (!exists($installedla{$File::Find::name})){
                        my $size = -s $File::Find::name;
                        $runningsize += -s $File::Find::name;
                        print "Orphan: ".$File::Find::name." ".KB($size)."\n";
                        }
         }
}

sub KB {
        my $num = $_[0]/1024;
        $num = sprintf("%.2f", $num);
        $num =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
        $num = $num." KB";
        return $num;
}
Back to top
View user's profile Send private message
dopey
Apprentice
Apprentice


Joined: 10 Feb 2003
Posts: 235

PostPosted: Tue Jun 13, 2006 10:32 pm    Post subject: Reply with quote

Thanks, glad someone else has time at work to do this :)

Makes perfect sense. And alot more scalable than equerying every single .la file.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum