From 82287bbbf111133ba59a62f33249e48e9861ee30 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 29 Mar 2015 18:12:57 +0200 Subject: [PATCH] Partial job IDs must start at the beginning of a component --- NOTES | 5 +++-- lib/perl/BEX/Queue.pm | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NOTES b/NOTES index 008fbd3..366a409 100644 --- a/NOTES +++ b/NOTES @@ -38,8 +38,9 @@ Prep: Run in a shell before the job body is executed; $HOST contains the name of the host. This is useful for example if you want to transfer data to the host by rsync. -Whenever a user command wants a job ID, it accepts any substring, as long as -it is unique. +Whenever a user command wants a job ID, it accepts any substring starting +at a component boundary (start of the ID or a "-"), as long as the substring +is unique. ### Status files ### diff --git a/lib/perl/BEX/Queue.pm b/lib/perl/BEX/Queue.pm index 9783fa0..9fb2428 100644 --- a/lib/perl/BEX/Queue.pm +++ b/lib/perl/BEX/Queue.pm @@ -96,6 +96,11 @@ sub all_job_ids($) { return @jobs; } +sub match_job_id($$) { + my ($id, $pattern) = @_; + return $id =~ m{\b$pattern}; +} + # Resolve a (possibly partial) job ID given by the user sub resolve_job_id($$) { my ($queue, $name) = @_; @@ -104,7 +109,7 @@ sub resolve_job_id($$) { return $name; } - my @candidates = map { index($_, $name) >= 0 ? $_ : () } $queue->all_job_ids(); + my @candidates = grep { match_job_id($_, $name) } $queue->all_job_ids(); @candidates or die "No job called $name exists\n"; @candidates == 1 or die "Partial job ID $name is not unique\n"; return $candidates[0]; -- 2.39.2