]> git.sur5r.net Git - bacula/bacula/commitdiff
- Add Version, ConfigDir, and WorkingDir as Python attributes
authorKern Sibbald <kern@sibbald.com>
Wed, 22 Jun 2005 19:12:20 +0000 (19:12 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 22 Jun 2005 19:12:20 +0000 (19:12 +0000)
  in the Director.
- Implement code (principally for Win32) that on failure to
  create a file, it will cd into the directory and attempt
  to create the file using a relative path. This avoids creating
  files with paths which fail on Win32.
- Fix parsing of times and sizes with decimal numbers.
- Make free_volume_list() in SD work if vol list is not
  initialized (./bacula-sd -t).

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2160 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kes-1.37
bacula/src/dird/dird.c
bacula/src/dird/pythondir.c
bacula/src/findlib/create_file.c
bacula/src/lib/edit.c
bacula/src/lib/parse_conf.c
bacula/src/stored/reserve.c
bacula/src/version.h

index 473aed3499c58319e4be872a53b3f67188c001d3..00364c6c7de32f6b6e6db17b113d2c30b85554ec 100644 (file)
@@ -4,6 +4,16 @@
 General:
 
 Changes to 1.37.26:
+22Jun05:
+- Add Version, ConfigDir, and WorkingDir as Python attributes
+  in the Director.
+- Implement code (principally for Win32) that on failure to
+  create a file, it will cd into the directory and attempt
+  to create the file using a relative path. This avoids creating
+  files with paths which fail on Win32.
+- Fix parsing of times and sizes with decimal numbers.
+- Make free_volume_list() in SD work if vol list is not
+  initialized (./bacula-sd -t).
 21Jun05:
 - Add debug error printout when open() fails.
 - If open() of DVD fails in mount.c, return false.
index 909533ad43431deb04531cee63612297bbf23de8..9d4aad320a45dbf4b0a6c684aef928e888bc1257 100644 (file)
@@ -45,7 +45,6 @@ void store_level(LEX *lc, RES_ITEM *item, int index, int pass);
 void store_replace(LEX *lc, RES_ITEM *item, int index, int pass);
 void init_device_resources();
 
-static char *configfile = NULL;
 static char *runjob = NULL;
 static int background = 1;
 static void init_reload(void);
@@ -54,6 +53,7 @@ static void init_reload(void);
 DIRRES *director;                     /* Director resource */
 int FDConnectTimeout;
 int SDConnectTimeout;
+char *configfile = NULL;
 
 /* Globals Imported */
 extern int r_first, r_last;           /* first and last resources */
index d7dbe335c8cfe63ca08416137efb5a90e6cfbc3d..f192f90b97d93932c995ec099e94b67c2c31e984 100644 (file)
@@ -29,6 +29,7 @@
 #undef _POSIX_C_SOURCE
 #include <Python.h>
 
+extern char *configfile;
 extern JCR *get_jcr_from_PyObject(PyObject *self);
 extern PyObject *find_method(PyObject *eventsObject, PyObject *method, 
          const char *name);
@@ -69,6 +70,9 @@ static struct s_vars getvars[] = {
    { N_("JobName"),    "s"},
    { N_("JobStatus"),  "s"},
    { N_("Priority"),   "i"},
+   { N_("Version"),    "s"},
+   { N_("ConfigFile"), "s"},
+   { N_("WorkingDir"), "s"},
 
    { NULL,             NULL}
 };
@@ -142,6 +146,12 @@ PyObject *job_getattr(PyObject *self, char *attrname)
       return Py_BuildValue(getvars[i].fmt, buf);
    case 13:                           /* Priority */
       return Py_BuildValue(getvars[i].fmt, jcr->JobPriority);
+   case 14:                           /* Version */
+      return Py_BuildValue(getvars[i].fmt, VERSION);
+   case 15:                           /* Config Dir */
+      return Py_BuildValue(getvars[i].fmt, configfile);
+   case 16:                           /* Working Dir */
+      return Py_BuildValue(getvars[i].fmt, director->working_directory);
    }
    bsnprintf(errmsg, sizeof(errmsg), "Attribute %s not found.", attrname);
 bail_out:
index 8b01761b77dbef65a5091cace88873b98d2f0c60..2bf9725f72c97a8da41a6f4bee16c243ca541d72 100644 (file)
@@ -141,7 +141,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
          attr->ofname[pnl] = 0;                 /* terminate path */
 
          if (!path_already_seen(jcr, attr->ofname, pnl)) {
-            Dmsg1(50, "Make path %s\n", attr->ofname);
+            Dmsg1(100, "Make path %s\n", attr->ofname);
             /*
              * If we need to make the directory, ensure that it is with
              * execute bit set (i.e. parent_mode), and preserve what already
@@ -170,9 +170,50 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
             Jmsg1(jcr, M_ERROR, 0, "bpkt already open fid=%d\n", bfd->fid);
             bclose(bfd);
          }
+         /*
+          * If the open fails, we attempt to cd into the directory
+          *  and create the file with a relative path rather than
+          *  the full absolute path.  This is for Win32 where
+          *  path names may be too long to create.
+          */
          if ((bopen(bfd, attr->ofname, mode, S_IRUSR | S_IWUSR)) < 0) {
             berrno be;
+            int stat;
             be.set_errno(bfd->berrno);
+            Dmsg2(000, "bopen failed errno=%d: ERR=%s\n", bfd->berrno,  
+               be.strerror(bfd->berrno));
+            if (pnl > 0) {
+               char savechr;
+               struct saved_cwd cwd;
+               savechr = attr->ofname[pnl];
+               attr->ofname[pnl] = 0;                 /* terminate path */
+               Dmsg1(000, "Do chdir %s\n", attr->ofname);
+               if (save_cwd(&cwd) != 0) {
+                  Jmsg0(jcr, M_ERROR, 0, _("Could not save_dirn"));
+                  attr->ofname[pnl] = savechr;
+                  return CF_ERROR;
+               }
+               if (chdir(attr->ofname) < 0) {
+                  Jmsg2(jcr, M_ERROR, 0, _("Could not chdir to %s: ERR=%s\n"),
+                        attr->ofname, be.strerror());
+                  restore_cwd(&cwd, NULL, NULL);
+                  free_cwd(&cwd);
+                  attr->ofname[pnl] = savechr;
+                  return CF_ERROR;
+               }
+               attr->ofname[pnl] = savechr;
+               Dmsg1(000, "Do open %s\n", &attr->ofname[pnl+1]);
+               if ((bopen(bfd, &attr->ofname[pnl+1], mode, S_IRUSR | S_IWUSR)) < 0) {
+                  stat = CF_ERROR;
+               } else {
+                  stat = CF_EXTRACT;
+               }
+               restore_cwd(&cwd, NULL, NULL);
+               free_cwd(&cwd);
+               if (stat == CF_EXTRACT) {
+                  return CF_EXTRACT;
+               }
+            }
             Jmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"),
                   attr->ofname, be.strerror());
             return CF_ERROR;
index 21ca18566dbceb9ceb01226b34dfeed4adead2dd..bcebed3909de38f54e68cbd15694cf4238d5fe78 100644 (file)
@@ -157,17 +157,13 @@ char *edit_int64(int64_t val, char *buf)
 
 
 /*
- * Given a string "str", separate the integer part into
+ * Given a string "str", separate the numeric part into
  *   str, and the modifier into mod.
  */
 static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_len)
 {
    int i, len, num_begin, num_end, mod_begin, mod_end;
 
-   /*
-    * Look for modifier by walking back looking for the first
-    *   space or digit.
-    */
    strip_trailing_junk(str);
    len = strlen(str);
 
@@ -180,7 +176,7 @@ static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_l
 
    /* Walk through integer part */
    for ( ; i<len; i++) {
-      if (!B_ISDIGIT(str[i])) {
+      if (!B_ISDIGIT(str[i]) && str[i] != '.') {
          break;
       }
    }
@@ -191,6 +187,7 @@ static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_l
    if (num_len == 0) {
       return false;
    }
+   /* Eat any spaces in front of modifier */
    for ( ; i<len; i++) {
       if (!B_ISSPACE(str[i])) {
          break;
@@ -214,6 +211,7 @@ static bool get_modifier(char *str, char *num, int num_len, char *mod, int mod_l
       return false;
    }
    bstrncpy(str, &str[mod_end], len);
+   Dmsg2(900, "num=%s mod=%s\n", num, mod);
 
    return true;
 }
index c86199e677809ca0f19cd01caf240e16a317da6f..41177e10479a36d0b293e535e1089f74386a477c 100755 (executable)
  *
  *   Version $Id$
  */
-
 /*
    Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -624,6 +618,7 @@ void store_size(LEX *lc, RES_ITEM *item, int index, int pass)
 {
    int token;
    uint64_t uvalue;
+   char bsize[500];
 
    Dmsg0(900, "Enter store_size\n");
    token = lex_get_token(lc, T_SKIP_EOL);
@@ -632,7 +627,18 @@ void store_size(LEX *lc, RES_ITEM *item, int index, int pass)
    case T_NUMBER:
    case T_IDENTIFIER:
    case T_UNQUOTED_STRING:
-      if (!size_to_uint64(lc->str, lc->str_len, &uvalue)) {
+      bstrncpy(bsize, lc->str, sizeof(bsize));  /* save first part */
+      /* if terminated by space, scan and get modifier */
+      if (lc->ch == ' ') {
+         token = lex_get_token(lc, T_ALL);
+         switch (token) {
+         case T_IDENTIFIER:
+         case T_UNQUOTED_STRING:
+            bstrncat(bsize, lc->str, sizeof(bsize));
+            break;
+         }
+      }
+      if (!size_to_uint64(bsize, strlen(bsize), &uvalue)) {
          scan_err1(lc, _("expected a size number, got: %s"), lc->str);
       }
       *(uint64_t *)(item->value) = uvalue;
@@ -660,7 +666,8 @@ void store_time(LEX *lc, RES_ITEM *item, int index, int pass)
    case T_NUMBER:
    case T_IDENTIFIER:
    case T_UNQUOTED_STRING:
-      bstrncpy(period, lc->str, sizeof(period));
+      bstrncpy(period, lc->str, sizeof(period));  /* get first part */
+      /* if terminated by space, scan and get modifier */
       if (lc->ch == ' ') {
          token = lex_get_token(lc, T_ALL);
          switch (token) {
index ba58b00fc26876035c59acc44d7a06a0d0f87ffb..e48b9817f3f1aa85540d3ba0a0af4bb2168f2ccb 100644 (file)
@@ -194,6 +194,9 @@ void create_volume_list()
 void free_volume_list()
 {
    VOLRES *vol;
+   if (!vol_list) {
+      return;
+   }
    for (vol=(VOLRES *)vol_list->first(); vol; vol=(VOLRES *)vol_list->next(vol)) {
       Dmsg1(000, "Unreleased Volume=%s\n", vol->vol_name);
    }
index d6a04265c58f4e4abe57fc6fe20f4561398f1f85..52122dc263c57a6f99d01e9d3636c5d16c65da2a 100644 (file)
@@ -1,8 +1,8 @@
 /* */
 #undef  VERSION
 #define VERSION "1.37.26"
-#define BDATE   "21 June 2005"
-#define LSMDATE "21Jun05"
+#define BDATE   "22 June 2005"
+#define LSMDATE "22Jun05"
 
 /* Debug flags */
 #undef  DEBUG