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

Modified Files:
        ChangeLog Engine.pm PkgVersion.pm 
Added Files:
        Finally.pm 
Log Message:
new finalizer mechanism

Index: PkgVersion.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/PkgVersion.pm,v
retrieving revision 1.541
retrieving revision 1.542
diff -u -d -r1.541 -r1.542
--- PkgVersion.pm       22 Mar 2006 00:14:17 -0000      1.541
+++ PkgVersion.pm       22 Mar 2006 04:00:31 -0000      1.542
@@ -31,7 +31,7 @@
                                          &get_arch &get_system_perl_version
                                          &get_path &eval_conditional 
&enforce_gcc
                                          &dpkg_lockwait &aptget_lockwait 
&lock_wait
-                                         &store_rename);
+                                         &store_rename &apt_available);
 use Fink::CLI qw(&print_breaking &print_breaking_stderr &rejoin_text
                                 &prompt_boolean &prompt_selection
                                 &should_skip_prompt &die_breaking);
@@ -4584,6 +4584,17 @@
                Fink::PkgVersion->dpkg_changed;
                delete $self->{_buildlock};
        }
+       
+       # This should be a good time to scan the packages
+       my $autoscan = !$config->has_param("AutoScanpackages")
+               || $config->param_boolean("AutoScanpackages");
+       if ($autoscan && apt_available) {
+               require Fink::Engine;
+               Fink::Engine::scanpackages(1, $self->get_full_tree);
+               Fink::Engine::finalize('apt-get update', sub {
+                       Fink::Engine::aptget_update();
+               });
+       }
 }
 
 =item ensure_gpp_prefix

Index: Engine.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Engine.pm,v
retrieving revision 1.360
retrieving revision 1.361
diff -u -d -r1.360 -r1.361
--- Engine.pm   22 Mar 2006 01:04:19 -0000      1.360
+++ Engine.pm   22 Mar 2006 04:00:30 -0000      1.361
@@ -34,6 +34,7 @@
                                 &prompt_boolean &prompt_selection
                                 &get_term_width);
 use Fink::Configure qw(&spotlight_warning);
+use Fink::Finally;
 use Fink::Package;
 use Fink::PkgVersion;
 use Fink::Config qw($config $basepath $debarch $dbpath);
@@ -123,6 +124,9 @@
          'show-deps'         => [\&cmd_show_deps,         1, 0, 0],
        );
 
+# Groups of finalizers for &process 
+our @finalizers = ({ });
+
 END { }                                # module clean-up code here (global 
destructor)
 
 ### constructor using configuration
@@ -183,6 +187,8 @@
                my @argv_stack = @{Fink::Config::get_option('_ARGV_stack', [])};
                push @argv_stack, [ @$orig_ARGV ];
                Fink::Config::set_options({ '_ARGV_stack' => [EMAIL PROTECTED] 
});
+               
+               push @finalizers, { }; # new finalizer group
        }
 
        ($proc, $pkgflag, $rootflag, $aptgetflag) = @{$commands{$cmd}};
@@ -287,6 +293,8 @@
                my @argv_stack = @{Fink::Config::get_option('_ARGV_stack', [])};
                pop @argv_stack;
                Fink::Config::set_options({ '_ARGV_stack' => [EMAIL PROTECTED] 
});
+               
+               pop @finalizers; # run current finalizer group
        }
 
        return $retval;;
@@ -614,6 +622,26 @@
        }
 }
 
+=item finalize
+
+  finalize $name, $code;
+
+Add some code that should run when I<&process> finishes. Only the first 
I<$code>
+for a given I<$name> is run, all later calls are ignored.
+
+Supports re-entrancy.
+
+=cut
+
+{
+       sub finalize {
+               my ($name, $code) = @_;
+               my $group = $finalizers[-1];
+               return if exists $group->{$name};
+               $group->{$name} = Fink::Finally->new($code);
+       }
+}              
+
 =item aptget_update
 
   aptget_update $quiet;
@@ -1895,14 +1923,6 @@
                        die "Problem resolving dependencies. Check for circular 
dependencies.\n";
                }
        }
-       
-       # Default to true
-       my $autoscan = !$config->has_param("AutoScanpackages")
-               || $config->param_boolean("AutoScanpackages");
-       if ($willbuild && $autoscan && apt_available) {
-               scanpackages(1);
-               aptget_update(1);
-       }
 }
 
 ### helper routines

--- NEW FILE: Finally.pm ---
# -*- mode: Perl; tab-width: 4; -*-
#
# Fink::Finally module
#
# Fink - a package manager that downloads source and installs it
# Copyright (c) 2006 The Fink Package Manager Team
#
# 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 the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA      02111-1307, 
USA.
#

package Fink::Finally;
use base 'Fink::Base';

use warnings;
use strict;

=head1 NAME

Fink::Finally - Run cleanup code unconditionally.

=head1 DESCRIPTION

Usually cleanup code runs explicitly, but sometimes exceptions can cause it
to be bypassed. Fink::Finally allows such code to be executed even if an
exception occurs.

=head1 SYNOPSIS

  use Fink::Finally;

  # $fin runs even if an exception is thrown
  my $fin = Fink::Finally->new(sub { ... });

  function_which_might_die();

  $fin->run;

=head1 METHODS

=over 4

=item new

  my $fin = Fink::Finally->new(sub { ... });

Create a finalizer to run the given cleanup code.

The code will run either when C<$finally->run> is called, or when I<$fin> goes
out of scope. The return value of the code is not accessible, since the caller
may not get a chance to explictly call I<&run>.

=cut

sub initialize {
        my ($self, $code) = @_;
        $self->SUPER::initialize;
        
        die "A Finally needs some code to run!\n"
                unless defined $code && ref($code) eq 'CODE';
        $self->{_code} = $code;
        $self->{_primed} = 1; # ready to go
}

=item run

  $fin->run;

Explicitly run the cleanup code in this finalizer.

If called multiple times, only the first will actually do anything.

=cut

sub run {
        my ($self) = @_;
        return unless $self->{_primed};
        
        &{$self->{_code}}();
        delete $self->{_primed};
}

sub DESTROY {
        $_[0]->run;
}

=item cancel

  $fin->cancel;

Do not allow this finalizer to run.

=cut

sub cancel {
        my ($self) = @_;
        delete $self->{_primed};
}

=back

=cut

1;

Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.1287
retrieving revision 1.1288
diff -u -d -r1.1287 -r1.1288
--- ChangeLog   22 Mar 2006 01:04:19 -0000      1.1287
+++ ChangeLog   22 Mar 2006 04:00:29 -0000      1.1288
@@ -1,5 +1,14 @@
 2006-03-21  Dave Vasilevsky  <[EMAIL PROTECTED]>
 
+       * Finally.pm: New way to create cleanup functions.
+       * Engine.pm: Adapt to new Finally, add 'finalizer' method to schedule a
+       function to run when process finishes.
+       * Engine.pm, PkgVersion.pm: Move AutoScanpackages to happen just after
+       buildlock removal for each package. The apt-get update is only run at 
the
+       end of a build, using the new finalizer mechanism.
+
+2006-03-21  Dave Vasilevsky  <[EMAIL PROTECTED]>
+
        * Services.pm: New function apt_available, to check if apt is around.
        * Engine.pm: Make things work with apt uninstalled.
 



-------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits

Reply via email to