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

Modified Files:
        ChangeLog Engine.pm Package.pm PkgVersion.pm Services.pm 
Log Message:
graceful failure for locking

Index: Services.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Services.pm,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -d -r1.198 -r1.199
--- Services.pm 17 Mar 2006 06:42:08 -0000      1.198
+++ Services.pm 19 Mar 2006 08:50:48 -0000      1.199
@@ -28,12 +28,13 @@
 use Fink::Command      qw(&rm_f);
 use Fink::CLI          qw(&word_wrap &get_term_width &print_breaking_stderr);
 
-use POSIX qw(uname tmpnam);
+use POSIX qw(uname tmpnam :errno_h);
 use Fcntl qw(:flock);
 use Getopt::Long;
 use Data::Dumper;
 use File::Find;
 use File::Spec;
+use Storable; # safe in the modern world
 
 use strict;
 use warnings;
@@ -67,7 +68,7 @@
                                          &store_rename &fix_gcc_repairperms
                                          &spec2struct &spec2string &get_options
                                          $VALIDATE_HELP $VALIDATE_ERROR 
$VALIDATE_OK
-                                         &find_subpackages);
+                                         &find_subpackages &lock_store 
&lock_retrieve);
 }
 our @EXPORT_OK;
 
@@ -1683,6 +1684,21 @@
        if (flock $lockfile_FH, $mode | LOCK_NB) {
                return wantarray ? ($lockfile_FH, 0) : $lockfile_FH;
        } else {
+               # Maybe the system doesn't support locking?
+               if ($! == EOPNOTSUPP || $! == ENOLCK) {
+                       require Fink::Config;
+                       if (!defined $Fink::Config::config ||
+                                       
!$Fink::Config::config->get_option("LockWarning", 0)) {
+                               # Try to warn only once
+                               print STDERR "WARNING: No locking is available 
on this " . 
+                                       "filesystem.\nTo ensure safety, do not 
run multiple " .
+                                       "instances simultaneously.\n";
+                               $Fink::Config::config->set_options({ 
LockWarning => 1 })
+                                       if defined $Fink::Config::config;
+                       }
+                       return ($lockfile_FH, 0);
+               }
+               
                return (wantarray ? (0, 0) : 0) if $no_block;
                
                # Couldn't get lock, meaning process has it
@@ -1785,7 +1801,7 @@
        my $tmp = "${file}.tmp";
        
        return 0 unless eval { require Storable };
-       if (Storable::lock_store($ref, $tmp)) {
+       if (&lock_store($ref, $tmp)) {
                unless (rename $tmp, $file) {
                        print_breaking_stderr("Error: could not activate 
temporary file $tmp: $!");
                        return 0;
@@ -2192,6 +2208,29 @@
        return @found;
 }
 
+=item lock_store, lock_retrieve
+
+Identical to Storable::lock_store and Storable::lock_retrieve, except that
+they fail gracefully when locking is unavailable.
+
+=cut
+
+sub lock_store {
+       my ($data, $file) = @_;
+       my $fh = lock_wait($file, exclusive => 1);
+       my $ret = Storable::store($data, $file);
+       close $fh;
+       return $ret;
+}
+
+sub lock_retrieve {
+       my ($file) = @_;
+       my $fh = lock_wait($file, shared => 1);
+       my $ret = Storable::retrieve($file);
+       close $fh;
+       return $ret;
+}
+
 =back
 
 =cut

Index: PkgVersion.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/PkgVersion.pm,v
retrieving revision 1.534
retrieving revision 1.535
diff -u -d -r1.534 -r1.535
--- PkgVersion.pm       17 Mar 2006 22:31:41 -0000      1.534
+++ PkgVersion.pm       19 Mar 2006 08:50:48 -0000      1.535
@@ -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 &lock_retrieve);
 use Fink::CLI qw(&print_breaking &print_breaking_stderr &rejoin_text
                                 &prompt_boolean &prompt_selection
                                 &should_skip_prompt &die_breaking);
@@ -171,7 +171,7 @@
 #                      print "Loading PkgVersion " . $self->get_fullname . " 
from: $file\n";
                        eval {
                                local $SIG{INT} = 'IGNORE'; # No user interrupts
-                               $loaded = Storable::lock_retrieve($file);
+                               $loaded = &lock_retrieve($file);
                        };
                        if ($@ || !defined $loaded) {
                                die "It appears that part of Fink's package 
database is corrupted "

Index: Engine.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Engine.pm,v
retrieving revision 1.356
retrieving revision 1.357
diff -u -d -r1.356 -r1.357
--- Engine.pm   17 Mar 2006 06:42:07 -0000      1.356
+++ Engine.pm   19 Mar 2006 08:50:47 -0000      1.357
@@ -614,85 +614,6 @@
        }
 }
 
-=item create_override
-
-  create_override(@trees);
-
-Create an override file for the Fink .debs. The override lock must be locked
-for this method to work.
-
-=cut
-
-sub create_override {
-       my @trees = @_;
-       my @pkgs;
-       
-       if (eval { require Storable; }) {
-               # Cache the old files. Not the most efficient system, but it 
has the
-               # benefit of only needing to fully scan a tree once, ever.
-               
-               my %pkgs;
-               my $dbpath = "$dbpath/override.db";
-               my $db = -f $dbpath ? Storable::lock_retrieve($dbpath) : { };
-               
-               for my $tree (@trees) {
-                       if (exists $db->{$tree}) {              # Use the 
cached debs
-                               my $debs = $db->{$tree};
-                               for my $deb (keys %$debs) {
-                                       if (-f $deb) {
-                                               $pkgs{$debs->{$deb}} = 1;
-#                                              print "Using no-prio: $deb\n";
-                                       } else {
-                                               delete $debs->{$deb};
-#                                              print "No-prio no longer 
exists: $deb\n";
-                                       }
-                               }
-                       } else {                                                
# Get the no-prio debs
-                               find(sub {
-                                       return unless /\.deb$/;
-                                       my %fields;
-                                       open DEB, "dpkg-deb -f \Q$_\E package 
priority |"
-                                               or return;
-                                       while (<DEB>) {
-                                               chomp;
-                                               if (/^(\S+)\s*:\s*(.*)$/) {
-                                                       $fields{lc $1} = $2;
-                                               }
-                                       }
-                                       close DEB;
-                                       
-                                       unless (exists $fields{priority}) {
-                                               
$db->{$tree}->{$File::Find::name} = $fields{'package'};
-                                               $pkgs{$fields{'package'}} = 1;
-#                                              print "Found no-prio: 
$File::Find::name\n";
-                                       } else {
-#                                              print "Have prio in: 
$File::Find::name\n";
-                                       }
-                               }, 
"$basepath/fink/dists/$tree/binary-$debarch/") if (-d 
"$basepath/fink/dists/$tree/binary-$debarch/");
-                       }
-               }
-               
-               store_rename($db, $dbpath);
-               @pkgs = keys %pkgs;
-       } else {
-               @pkgs = Fink::Package->list_packages();
-       }
-       
-       open(OVERRIDE,">$basepath/fink/override") or die "can't write override 
file: $!\n";
-       foreach my $pkgname (@pkgs) {
-               my ($package, $pkgversion, $prio, $section);
-               $package = Fink::Package->package_by_name($pkgname);
-               next unless defined $package;
-               $pkgversion = 
$package->get_version(&latest_version($package->list_versions()));
-               next unless defined $pkgversion;
-
-               $section = $pkgversion->get_control_section();
-               $prio = $pkgversion->get_priority();
-               print OVERRIDE "$pkgname $prio $section\n";
-       }
-       close(OVERRIDE) or die "can't write override file: $!\n";
-}
-
 
 sub cmd_scanpackages {
        my $quiet = shift || 0;

Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v
retrieving revision 1.1272
retrieving revision 1.1273
diff -u -d -r1.1272 -r1.1273
--- ChangeLog   19 Mar 2006 04:06:26 -0000      1.1272
+++ ChangeLog   19 Mar 2006 08:50:47 -0000      1.1273
@@ -1,3 +1,9 @@
+2006-03-19  Dave Vasilevsky  <[EMAIL PROTECTED]>
+
+       * Engine.pm: We don't need the 'override' code anymore, yay!
+       * Package.pm, PkgVersion.pm, Services.pm: Fail gracefully if locking is
+       not supported.
+
 2006-03-18  Dave Vasilevsky  <[EMAIL PROTECTED]>
 
        * Scanpackages.pm: Let's NOT delete files for no good reason.

Index: Package.pm
===================================================================
RCS file: /cvsroot/fink/fink/perlmod/Fink/Package.pm,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- Package.pm  17 Mar 2006 06:42:07 -0000      1.169
+++ Package.pm  19 Mar 2006 08:50:47 -0000      1.170
@@ -25,7 +25,7 @@
 use Fink::Base;
 use Fink::Services qw(&read_properties &read_properties_var
                      &latest_version &version_cmp &parse_fullversion
-                     &expand_percent &lock_wait &store_rename);
+                     &expand_percent &lock_wait &store_rename &lock_retrieve);
 use Fink::CLI qw(&get_term_width &print_breaking &print_breaking_stderr
                                 &rejoin_text);
 use Fink::Config qw($config $basepath $dbpath $debarch);
@@ -963,7 +963,7 @@
                $valid_since = (stat($class->db_proxies))[9];
                eval {
                        local $SIG{INT} = 'IGNORE'; # No user interrupts
-                       $packages = Storable::lock_retrieve($class->db_proxies);
+                       $packages = &lock_retrieve($class->db_proxies);
                };
                if ($@ || !defined $packages) {
                        die "It appears that part of Fink's package database is 
corrupted. "
@@ -979,7 +979,7 @@
                if ($idx_ok) {
                        eval {
                                local $SIG{INT} = 'IGNORE'; # No user interrupts
-                               $idx = 
Storable::lock_retrieve($class->db_index);
+                               $idx = &lock_retrieve($class->db_index);
                        };
                        if ($@ || !defined $idx) {
                                close $lock if $lock;



-------------------------------------------------------
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