]> mj.ucw.cz Git - bex.git/commitdiff
Partial job IDs must start at the beginning of a component
authorMartin Mares <mj@ucw.cz>
Sun, 29 Mar 2015 16:12:57 +0000 (18:12 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 29 Mar 2015 16:12:57 +0000 (18:12 +0200)
NOTES
lib/perl/BEX/Queue.pm

diff --git a/NOTES b/NOTES
index 008fbd38a7c7c0be27552a5d400db3cbdf61eef9..366a4092130fad07a487870524b62fc4c8f9d4df 100644 (file)
--- a/NOTES
+++ b/NOTES
@@ -38,8 +38,9 @@ Prep: <command>                       Run <command> 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 ###
 
index 9783fa071b288f89948f16816fda40eb71fda3e2..9fb242879178209afce1b47be96602076aec26c8 100644 (file)
@@ -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];