From: Kern Sibbald Date: Wed, 22 Jun 2005 19:12:20 +0000 (+0000) Subject: - Add Version, ConfigDir, and WorkingDir as Python attributes X-Git-Tag: Release-7.0.0~8671 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=96d7574122b9ffe629d3084c8fa4f575dfffccdc;p=bacula%2Fbacula - 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). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2160 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index 473aed3499..00364c6c7d 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -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. diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 909533ad43..9d4aad320a 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -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 */ diff --git a/bacula/src/dird/pythondir.c b/bacula/src/dird/pythondir.c index d7dbe335c8..f192f90b97 100644 --- a/bacula/src/dird/pythondir.c +++ b/bacula/src/dird/pythondir.c @@ -29,6 +29,7 @@ #undef _POSIX_C_SOURCE #include +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: diff --git a/bacula/src/findlib/create_file.c b/bacula/src/findlib/create_file.c index 8b01761b77..2bf9725f72 100644 --- a/bacula/src/findlib/create_file.c +++ b/bacula/src/findlib/create_file.c @@ -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; diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index 21ca18566d..bcebed3909 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -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 ( ; istr, 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) { diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index ba58b00fc2..e48b9817f3 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -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); } diff --git a/bacula/src/version.h b/bacula/src/version.h index d6a04265c5..52122dc263 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -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