+/*
+ * Copy the storage definitions from an alist to the JCR
+ */
+void copy_rwstorage(JCR *jcr, alist *storage, const char *where)
+{
+ switch(jcr->JobType) {
+ case JT_RESTORE:
+ case JT_VERIFY:
+ case JT_MIGRATE:
+ copy_rstorage(jcr, storage, where);
+ break;
+ default:
+ copy_wstorage(jcr, storage, where);
+ break;
+ }
+}
+
+
+/* Set storage override. Releases any previous storage definition */
+void set_rwstorage(JCR *jcr, USTORE *store)
+{
+ if (!store) {
+ Jmsg(jcr, M_FATAL, 0, _("No storage specified.\n"));
+ return;
+ }
+ switch(jcr->JobType) {
+ case JT_RESTORE:
+ case JT_VERIFY:
+ case JT_MIGRATE:
+ set_rstorage(jcr, store);
+ break;
+ default:
+ set_wstorage(jcr, store);
+ break;
+ }
+}
+
+void free_rwstorage(JCR *jcr)
+{
+ free_rstorage(jcr);
+ free_wstorage(jcr);
+}
+
+/*
+ * Copy the storage definitions from an alist to the JCR
+ */
+void copy_rstorage(JCR *jcr, alist *storage, const char *where)
+{
+ if (storage) {
+ STORE *st;
+ if (jcr->rstorage) {
+ delete jcr->rstorage;
+ }
+ jcr->rstorage = New(alist(10, not_owned_by_alist));
+ foreach_alist(st, storage) {
+ jcr->rstorage->append(st);
+ }
+ if (!jcr->rstore_source) {
+ jcr->rstore_source = get_pool_memory(PM_MESSAGE);
+ }
+ pm_strcpy(jcr->rstore_source, where);
+ if (jcr->rstorage) {
+ jcr->rstore = (STORE *)jcr->rstorage->first();
+ }
+ }
+}
+
+
+/* Set storage override. Remove all previous storage */
+void set_rstorage(JCR *jcr, USTORE *store)
+{
+ STORE *storage;
+
+ if (!store->store) {
+ return;
+ }
+ if (jcr->rstorage) {
+ free_rstorage(jcr);
+ }
+ if (!jcr->rstorage) {
+ jcr->rstorage = New(alist(10, not_owned_by_alist));
+ }
+ jcr->rstore = store->store;
+ if (!jcr->rstore_source) {
+ jcr->rstore_source = get_pool_memory(PM_MESSAGE);
+ }
+ pm_strcpy(jcr->rstore_source, store->store_source);
+ foreach_alist(storage, jcr->rstorage) {
+ if (store->store == storage) {
+ return;
+ }
+ }
+ /* Store not in list, so add it */
+ jcr->rstorage->prepend(store->store);
+}
+
+void free_rstorage(JCR *jcr)
+{
+ if (jcr->rstorage) {
+ delete jcr->rstorage;
+ jcr->rstorage = NULL;
+ }
+ jcr->rstore = NULL;
+}