From: Martin Mares Date: Sun, 29 Mar 2015 16:12:57 +0000 (+0200) Subject: Partial job IDs must start at the beginning of a component X-Git-Tag: v3.3~2 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=82287bbbf111133ba59a62f33249e48e9861ee30;p=bex.git Partial job IDs must start at the beginning of a component --- 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];