From ebb83464d50f7021891a9b3857cb210aef4a50ac Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Thu, 18 Feb 2016 15:06:56 +0100 Subject: [PATCH] dird: Add support for non-interactive label barcodes. We should not ask for confirmation in batch mode and accept the yes keyword as indication that we should not be interactive like we do in other situations. Also add the drive argument to label which is needed when we have a multidrive autochanger. --- src/dird/ua_cmds.c | 12 ++++++------ src/dird/ua_label.c | 29 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/dird/ua_cmds.c b/src/dird/ua_cmds.c index c1d9e1f5c74..0984718b584 100644 --- a/src/dird/ua_cmds.c +++ b/src/dird/ua_cmds.c @@ -137,7 +137,7 @@ static struct cmdstruct commands[] = { { NT_("import"), import_cmd, _("Import volumes from import/export slots to normal slots"), NT_("storage= [ srcslots= dstslots= volume= scan ]"), true, true }, { NT_("label"), label_cmd, _("Label a tape"), - NT_("storage= volume= pool= slot= [ barcodes ] [ encrypt ]"), false, true }, + NT_("storage= volume= pool= slot= [ drive = ] [ barcodes ] [ encrypt ] [ yes ]"), false, true }, { NT_("list"), list_cmd, _("List objects from catalog"), NT_("basefiles jobid= | basefiles ujobid= |\n" "backups client= [fileset=] [jobstatus=] [level=] [order=] [limit=] |\n" @@ -188,7 +188,7 @@ static struct cmdstruct commands[] = { { NT_("memory"), memory_cmd, _("Print current memory usage"), NT_(""), true, false }, { NT_("mount"), mount_cmd, _("Mount storage"), - NT_("storage= slot= drive=\n" + NT_("storage= slot= drive=\n" "\tjobid= | job= | ujobid="), false, true }, { NT_("move"), move_cmd, _("Move slots in an autochanger"), NT_("storage= srcslots= dstslots="), true, true }, @@ -196,7 +196,7 @@ static struct cmdstruct commands[] = { NT_("files | jobs | jobtype= | pool= | client= | volume= | directory= | recursive"), true, true }, { NT_("purge"), purge_cmd, _("Purge records from catalog"), NT_("files jobs volume= [ action= devicetype= pool=\n" - "\tallpools storage= drive= ]"), true, true }, + "\tallpools storage= drive= ]"), true, true }, { NT_("quit"), quit_cmd, _("Terminate Bconsole session"), NT_(""), false, false }, { NT_("query"), query_cmd, _("Query catalog"), @@ -213,7 +213,7 @@ static struct cmdstruct commands[] = { NT_("storage= oldvolume=\n" "\tvolume= pool= [ encrypt ]"), false, true }, { NT_("release"), release_cmd, _("Release storage"), - NT_("storage= [ drive= ] [ alldrives ]"), false, true }, + NT_("storage= [ drive= ] [ alldrives ]"), false, true }, { NT_("reload"), reload_cmd, _("Reload conf file"), NT_(""), true, true }, { NT_("rerun"), rerun_cmd, _("Rerun a job"), @@ -252,10 +252,10 @@ static struct cmdstruct commands[] = { { NT_("trace"), trace_cmd, _("Turn on/off trace to file"), NT_("on | off"), true, true }, { NT_("unmount"), unmount_cmd, _("Unmount storage"), - NT_("storage= [ drive= ]\n" + NT_("storage= [ drive= ]\n" "\tjobid= | job= | ujobid="), false, true }, { NT_("umount"), unmount_cmd, _("Umount - for old-time Unix guys, see unmount"), - NT_("storage= [ drive= ]\n" + NT_("storage= [ drive= ]\n" "\tjobid= | job= | ujobid="), false, true }, { NT_("update"), update_cmd, _("Update volume, pool or stats"), NT_("stats\n" diff --git a/src/dird/ua_label.c b/src/dird/ua_label.c index 059dd6b3b7a..ff5e83daa90 100644 --- a/src/dird/ua_label.c +++ b/src/dird/ua_label.c @@ -30,7 +30,8 @@ #include "dird.h" /* Forward referenced functions */ -static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt); +static void label_from_barcodes(UAContext *ua, int drive, + bool label_encrypt, bool yes); static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr, POOL_DBR *pr, bool relabel, bool media_record_exists, int drive); @@ -75,18 +76,19 @@ static inline bool is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr) */ static int do_label(UAContext *ua, const char *cmd, bool relabel) { - USTORERES store; + int i, j; + int drive; BSOCK *sd; - char dev_name[MAX_NAME_LENGTH]; MEDIA_DBR mr, omr; POOL_DBR pr; + USTORERES store; + bool ok = false; + bool yes = false; /* Was "yes" given on cmdline */ bool print_reminder = true; bool label_barcodes = false; bool label_encrypt = false; - int ok = FALSE; - int i, j; - int drive; bool media_record_exists = false; + char dev_name[MAX_NAME_LENGTH]; static const char *barcode_keywords[] = { "barcode", "barcodes", @@ -101,6 +103,10 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel) memset(&mr, 0, sizeof(mr)); memset(&omr, 0, sizeof(omr)); + if (ua->batch || find_arg(ua, NT_("yes")) > 0) { + yes = true; + } + /* * Look for one of the barcode keywords */ @@ -152,7 +158,7 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel) drive = get_storage_drive(ua, store.store); if (label_barcodes) { - label_from_barcodes(ua, drive, label_encrypt); + label_from_barcodes(ua, drive, label_encrypt, yes); return 1; } @@ -276,7 +282,6 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel) } ok = send_label_request(ua, &mr, &omr, &pr, relabel, media_record_exists, drive); - if (ok) { sd = ua->jcr->store_bsock; if (relabel) { @@ -346,7 +351,8 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel) /* * Request SD to send us the slot:barcodes, then wiffle through them all labeling them. */ -static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt) +static void label_from_barcodes(UAContext *ua, int drive, + bool label_encrypt, bool yes) { STORERES *store = ua->jcr->res.wstore; POOL_DBR pr; @@ -389,10 +395,13 @@ static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt) } ua->send_msg("%4d %s\n", vl->Slot, vl->VolName); } - if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) || + + if (!yes || + !get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) || (ua->pint32_val == 0)) { goto bail_out; } + /* * Select a pool */