]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_select.c
03Dec05
[bacula/bacula] / bacula / src / dird / ua_select.c
index e734204ddd999b95c3ec74cf2b483c179317eaf6..41765194a59b1a89e85b3759dc9d6c5c6c5fa2eb 100644 (file)
@@ -149,7 +149,9 @@ STORE *select_storage_resource(UAContext *ua)
       }
    }
    UnlockRes();
-   do_prompt(ua, _("Storage"),  _("Select Storage resource"), name, sizeof(name));
+   if (do_prompt(ua, _("Storage"),  _("Select Storage resource"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
    store = (STORE *)GetResWithName(R_STORAGE, name);
    return store;
 }
@@ -170,7 +172,9 @@ FILESET *select_fileset_resource(UAContext *ua)
       }
    }
    UnlockRes();
-   do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name));
+   if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
    fs = (FILESET *)GetResWithName(R_FILESET, name);
    return fs;
 }
@@ -202,7 +206,9 @@ CAT *get_catalog_resource(UAContext *ua)
          }
       }
       UnlockRes();
-      do_prompt(ua, _("Catalog"),  _("Select Catalog resource"), name, sizeof(name));
+      if (do_prompt(ua, _("Catalog"),  _("Select Catalog resource"), name, sizeof(name)) < 0) {
+         return NULL;
+      }
       catalog = (CAT *)GetResWithName(R_CATALOG, name);
    }
    return catalog;
@@ -225,7 +231,9 @@ JOB *select_job_resource(UAContext *ua)
       }
    }
    UnlockRes();
-   do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name));
+   if (do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
    job = (JOB *)GetResWithName(R_JOB, name);
    return job;
 }
@@ -246,7 +254,9 @@ JOB *select_restore_job_resource(UAContext *ua)
       }
    }
    UnlockRes();
-   do_prompt(ua, _("Job"), _("Select Restore Job"), name, sizeof(name));
+   if (do_prompt(ua, _("Job"), _("Select Restore Job"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
    job = (JOB *)GetResWithName(R_JOB, name);
    return job;
 }
@@ -269,7 +279,9 @@ CLIENT *select_client_resource(UAContext *ua)
       }
    }
    UnlockRes();
-   do_prompt(ua, _("Client"),  _("Select Client (File daemon) resource"), name, sizeof(name));
+   if (do_prompt(ua, _("Client"),  _("Select Client (File daemon) resource"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
    client = (CLIENT *)GetResWithName(R_CLIENT, name);
    return client;
 }
@@ -551,7 +563,9 @@ POOL *select_pool_resource(UAContext *ua)
       }
    }
    UnlockRes();
-   do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name));
+   if (do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name)) < 0) {
+      return NULL;
+   }
    pool = (POOL *)GetResWithName(R_POOL, name);
    return pool;
 }
@@ -673,12 +687,16 @@ void add_prompt(UAContext *ua, const char *prompt)
  *  Returns: -1 on error
  *            index base 0 on success, and choice
  *               is copied to prompt if not NULL
+ *             prompt is set to the chosen prompt item string
  */
 int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt)
 {
    int i, item;
    char pmsg[MAXSTRING];
 
+   if (prompt) {
+      *prompt = 0;
+   }
    if (ua->num_prompts == 2) {
       item = 1;
       if (prompt) {
@@ -698,15 +716,11 @@ int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt,
       bsendmsg(ua, "%6d: %s\n", i, ua->prompt[i]);
    }
 
-   if (prompt) {
-      *prompt = 0;
-   }
-
    for ( ;; ) {
       /* First item is the prompt string, not the items */
       if (ua->num_prompts == 1) {
          bsendmsg(ua, _("Selection is empty!\n"));
-         item = 0;                    /* list is empty ! */
+         item = -1;                    /* list is empty ! */
          break;
       }
       if (ua->num_prompts == 2) {
@@ -741,7 +755,7 @@ done:
       free(ua->prompt[i]);
    }
    ua->num_prompts = 0;
-   return item - 1;
+   return item>0 ? item-1 : item;
 }
 
 
@@ -770,6 +784,7 @@ STORE *get_storage_resource(UAContext *ua, bool use_default)
          /* Ignore slots, scan and barcode(s) keywords */
          if (strcasecmp("scan", ua->argk[i]) == 0 ||
              strcasecmp("barcode", ua->argk[i]) == 0 ||
+             strcasecmp("barcodes", ua->argk[i]) == 0 ||
              strcasecmp("slots", ua->argk[i]) == 0) {
             continue;
          }
@@ -822,7 +837,7 @@ STORE *get_storage_resource(UAContext *ua, bool use_default)
       store = NULL;
    }
 
-   if (!store && store_name) {
+   if (!store && store_name && store_name[0] != 0) {
       store = (STORE *)GetResWithName(R_STORAGE, store_name);
       if (!store) {
          bsendmsg(ua, _("Storage resource \"%s\": not found\n"), store_name);
@@ -838,6 +853,7 @@ STORE *get_storage_resource(UAContext *ua, bool use_default)
    return store;
 }
 
+/* Get drive that we are working with for this storage */
 int get_storage_drive(UAContext *ua, STORE *store)
 {
    int i, drive = -1;
@@ -846,12 +862,22 @@ int get_storage_drive(UAContext *ua, STORE *store)
    if (i >=0) {
       drive = atoi(ua->argv[i]);
    } else if (store && store->autochanger) {
-      ua->cmd[0] = 0;
-      if (!get_cmd(ua, _("Enter autochanger drive[0]: "))) {
-         drive = -1;  /* None */
-      } else {
-         drive = atoi(ua->cmd);
+      /* If our structure is not set ask SD for # drives */
+      if (store->drives == 0) {
+         store->drives = get_num_drives_from_SD(ua);
       }
+      /* If only one drive, default = 0 */
+      if (store->drives == 1) {
+         drive = 0;
+      } else {
+         /* Ask user to enter drive number */
+         ua->cmd[0] = 0;
+         if (!get_cmd(ua, _("Enter autochanger drive[0]: "))) {
+            drive = -1;  /* None */
+         } else {
+            drive = atoi(ua->cmd);
+         }
+     }
    }
    return drive;
 }