]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/butil.c
added WSACleanup(), corrected WSA_Init() (removed #ifdef)
[bacula/bacula] / bacula / src / stored / butil.c
index 1e1387cf4bd3b2a0594c3cc8fcf7408571bd108c..4d439b5048a49c4112c72bc34433d27816355895 100644 (file)
@@ -92,14 +92,16 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
    }
 
    if ((device=find_device_res(jcr->dev_name, read_access)) == NULL) {
-      Jmsg2(jcr, M_FATAL, 0, _("Cannot find device %s in config file %s.\n"), 
+      Jmsg2(jcr, M_FATAL, 0, _("Cannot find device \"%s\" in config file %s.\n"), 
           jcr->dev_name, configfile);
       return NULL;
    }
    jcr->device = device;
+   pm_strcpy(&jcr->dev_name, device->device_name);
    
    dev = init_dev(NULL, device);
    jcr->device->dev = dev;
+   new_dcr(jcr, dev);       
    if (!dev || !first_open_device(dev)) {
       Jmsg1(jcr, M_FATAL, 0, _("Cannot open %s\n"), jcr->dev_name);
       return NULL;
@@ -126,23 +128,39 @@ DEVICE *setup_to_access_device(JCR *jcr, int read_access)
  */
 DEVRES *find_device_res(char *device_name, int read_access)
 {
-   int found = 0;
+   bool found = false;
    DEVRES *device;
 
    LockRes();
-   for (device=NULL; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
+   foreach_res(device, R_DEVICE) {
       if (strcmp(device->device_name, device_name) == 0) {
-        found = 1;
+        found = true;
         break;
       }
    } 
+   if (!found) {
+      /* Search for name of Device resource rather than archive name */
+      if (device_name[0] == '"') {
+        strcpy(device_name, device_name+1);
+        int len = strlen(device_name);
+        if (len > 0) {
+           device_name[len-1] = 0;
+        }
+      }
+      foreach_res(device, R_DEVICE) {
+        if (strcmp(device->hdr.name, device_name) == 0) {
+           found = true;
+           break;
+        }
+      } 
+   }
    UnlockRes();
    if (!found) {
-      Pmsg2(0, _("Could not find device %s in config file %s.\n"), device_name,
+      Pmsg2(0, _("Could not find device \"%s\" in config file %s.\n"), device_name,
            configfile);
       return NULL;
    }
-   Pmsg2(0, _("Using device: %s for %s.\n"), device_name,
+   Pmsg2(0, _("Using device: \"%s\" for %s.\n"), device_name,
              read_access?"reading":"writing");
    return device;
 }