Update of /cvsroot/fink/fink/perlmod/Fink
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23794

Modified Files:
        ChangeLog PkgVersion.pm Status.pm 
Log Message:
Abolish Status::invalidate...check dpkg status db file flags to see if
file has changed since we cached it


Index: Status.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Status.pm,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- Status.pm   3 Jan 2006 20:14:46 -0000       1.20
+++ Status.pm   1 Mar 2006 06:15:28 -0000       1.21
@@ -77,23 +77,26 @@
        $hash = {};
 
        if (not $config->want_magic_tree('status')) {
-               $self->{_invalid} = 0;
                return;
        }
 
        if (! -f $file) {
                print "WARNING: can't read dpkg status file \"$file\".\n";
-
-               $self->{_invalid} = 0;
                return;
        }
 
        open(IN,$file) or die "can't open $file: $!";
+
+       # store info about the db file we're caching
+       # (dpkg writes to a tempfile, then renames it to replace old)
+       ($self->{_db_ino}, $self->{_db_mtime}) = (stat IN)[1,9];
+
        while (<IN>) {
                chomp;
                if (/^([0-9A-Za-z_.\-]+)\:\s*(\S.*?)\s*$/) {
                        $hash->{lc $1} = $2;
                } elsif (/^\s*$/) {
+                       # line of just whitespace separates packages entries in 
the file
                        if (exists $hash->{package}) {
                                $self->{$hash->{package}} = $hash;
                        }
@@ -103,39 +106,27 @@
        }
        close(IN);
 
+       # handle last pkg entry in file (maybe no whitespace line after it)
        if (exists $hash->{package}) {
                $self->{$hash->{package}} = $hash;
        }
-
-       $self->{_invalid} = 0;
 }
 
-### update cached data if necessary
+### update cached data if db file on disk has changed
 
 sub validate {
        my $self = shift;
 
-       if ($self->{_invalid}) {
+       my(@db_stat) = stat $basepath.'/var/lib/dpkg/status';
+       unless (
+               @db_stat
+               and $self->{_db_ino} == $db_stat[1]
+               and $self->{_db_mtime} == $db_stat[9]
+       ) {
                $self->read();
        }
 }
 
-### invalidate cached data
-
-sub invalidate {
-       my $self = shift;
-
-       if (not ref($self)) {
-               if (defined($the_instance)) {
-                       $self = $the_instance;
-               } else {
-                       $self = Fink::Status->new();
-               }
-       }
-
-       $self->{_invalid} = 1;
-}
-
 ### query by package name
 # returns false when not installed
 # returns full version when installed and configured

Index: PkgVersion.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/PkgVersion.pm,v
retrieving revision 1.528
retrieving revision 1.529
diff -u -d -r1.528 -r1.529
--- PkgVersion.pm       28 Feb 2006 19:03:42 -0000      1.528
+++ PkgVersion.pm       1 Mar 2006 06:15:27 -0000       1.529
@@ -5042,7 +5042,6 @@
 =cut
 
 sub dpkg_changed {
-       Fink::Status->invalidate();
        Fink::Shlibs->invalidate();
 }
 

Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.1255
retrieving revision 1.1256
diff -u -d -r1.1255 -r1.1256
--- ChangeLog   28 Feb 2006 19:03:42 -0000      1.1255
+++ ChangeLog   1 Mar 2006 06:15:27 -0000       1.1256
@@ -1,3 +1,10 @@
+2006-03-01  Daniel Macks  <[EMAIL PROTECTED]>
+
+       * Status.pm: Instead of manually toggling _invalid, store data
+       about dpkg status file when reading it, compare stored vs actual
+       to determine whether cache is stale.
+       * PkgVersion.pm, Status.pm: Abolish Status::invalidate
+
 2006-02-28  Dave Vasilevsky  <[EMAIL PROTECTED]>
 
        * SysState.pm:



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Fink-commits mailing list
Fink-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fink-commits

Reply via email to