From 2be13e4ae8bda6d4121e44855871b3f622ce0a40 Mon Sep 17 00:00:00 2001 From: Doug Kingston Date: Sun, 17 Nov 2013 21:27:19 -0800 Subject: [PATCH 7/7] Bug 11078 Add locking to rebuild_zebra QA Patch 5 Address concern on the initialization of $lockdir. If lockdir is undef, then it will default to /var/lock. If lockdir is specified in the config, it is expected to be a valid directory. mkpath() will fail if its not a valid path. --- misc/migration_tools/rebuild_zebra.pl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 74976c1..702377c 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -143,8 +143,7 @@ my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaFi # We need to create our own lock directory which incorporates the database instance # we are indexing to facilitate multiple instances on the same machine. -my $lockdir = C4::Context->config("lockdir"); -$lockdir = "/var/lock" if $lockdir == ""; +my $lockdir = C4::Context->config("lockdir") // "/var/lock"; $lockdir .= ("/koha_rebuild_zebra_" . C4::Context->config("database")); mkpath($lockdir, 0, oct(755)) unless (-d $lockdir); my $lockfile = $lockdir . "/lock"; @@ -177,17 +176,17 @@ open my $LockFH, q{>}, $lockfile or die "$lockfile: $!"; if ($daemon_mode) { while (1) { # For incremental updates, skip the update if the updates are locked - if (flock(LockFH, LOCK_EX|LOCK_NB)) { + if (flock($LockFH, LOCK_EX|LOCK_NB)) { do_one_pass() if ( zebraqueue_not_empty() ); - flock(LockFH, LOCK_UN); + flock($LockFH, LOCK_UN); } sleep $daemon_sleep; } } else { # all one-off invocations, wait for the lock to free - flock(LockFH, LOCK_EX); + flock($LockFH, LOCK_EX); do_one_pass(); - flock(LockFH, LOCK_UN); + flock($LockFH, LOCK_UN); } -- 1.7.9.5