From 3e56eb19b63a6a0b2ed08d532dd7f54f71d7877b Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 28 Feb 2014 22:11:17 +0000 Subject: [PATCH] Bug 11078: (follow-up) tidy code - fix a couple typos in comments - make replace a "$i" with a more descriptive variable name - style some of the new code Signed-off-by: Galen Charlton (cherry picked from commit 160c44d4e9f529fc6e6ecbdab23ffab6bce5630e) Signed-off-by: Fridolin Somers --- misc/migration_tools/rebuild_zebra.pl | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index de3894fa7b..83e32c4f79 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -164,7 +164,11 @@ my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaFi # always work. my ($lockfile, $LockFH); -foreach( C4::Context->config("zebra_lockdir"), "/var/lock/zebra_".C4::Context->config('database'), "/tmp/zebra_".C4::Context->config('database') ) { +foreach ( + C4::Context->config("zebra_lockdir"), + '/var/lock/zebra_' . C4::Context->config('database'), + '/tmp/zebra_' . C4::Context->config('database') +) { #we try three possibilities (we really want to lock :) next if !$_; ($LockFH, $lockfile) = _create_lockfile($_.'/rebuild'); @@ -174,8 +178,10 @@ if( !defined $LockFH ) { print "WARNING: Could not create lock file $lockfile: $!\n"; print "Please check your koha-conf.xml for ZEBRA_LOCKDIR.\n"; print "Verify file permissions for it too.\n"; - $use_flock=0; #we disable file locking now and will continue without it - #note that this mimics old behavior (before we used the lockfile) + $use_flock = 0; # we disable file locking now and will continue + # without it + # note that this mimics old behavior (before we used + # the lockfile) }; if ( $verbose_logging ) { @@ -193,10 +199,10 @@ if ( $verbose_logging ) { my $tester = XML::LibXML->new(); # The main work is done here by calling do_one_pass(). We have added locking -# avoid race conditions between Full rebuilds and incremental updates either from +# avoid race conditions between full rebuilds and incremental updates either from # daemon mode or periodic invocation from cron. The race can lead to an updated # record being overwritten by a rebuild if the update is applied after the export -# by the rebuild and before the rebuild finishes (more likely to effect large +# by the rebuild and before the rebuild finishes (more likely to affect large # catalogs). # # We have chosen to exit immediately by default if we cannot obtain the lock @@ -218,8 +224,7 @@ if ($daemon_mode) { if (_flock($LockFH, $lock_mode)) { do_one_pass(); _flock($LockFH, LOCK_UN); - } - else { + } else { print "Skipping rebuild/update because flock failed on $lockfile: $!\n"; } } @@ -776,20 +781,21 @@ sub do_indexing { } sub _flock { -# test if flock is present; if so, use it; if not, return true -# op refers to the official flock operations incl LOCK_EX, LOCK_UN, etc. -# combining LOCK_EX with LOCK_NB returns immediately + # test if flock is present; if so, use it; if not, return true + # op refers to the official flock operations including LOCK_EX, + # LOCK_UN, etc. + # combining LOCK_EX with LOCK_NB returns immediately my ($fh, $op)= @_; if( !defined($use_flock) ) { #check if flock is present; if not, you will have a fatal error - my $i=eval { flock($fh, $op) }; - #assuming that $fh and $op are fine(..), an undef i means no flock - $use_flock= defined($i)? 1: 0; + my $lock_acquired = eval { flock($fh, $op) }; + # assuming that $fh and $op are fine(..), an undef $lock_acquired + # means no flock + $use_flock = defined($lock_acquired) ? 1 : 0; print "Warning: flock could not be used!\n" if $verbose_logging && !$use_flock; return 1 if !$use_flock; - return $i; - } - else { + return $lock_acquired; + } else { return 1 if !$use_flock; return flock($fh, $op); } -- 2.39.5