From fad9c10997f0fc3f8af2b84998e2cf1e9946ed3c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 12 Oct 2005 15:36:56 +0000 Subject: [PATCH] - Add a .dir command that separates arguments with commas. It is intended to be used in the tree routines to get a machine readable output for GUIs like wx-console. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2435 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 2 ++ bacula/kes-1.37 | 3 ++ bacula/src/dird/ua_tree.c | 63 +++++++++++++++++++++++++++++---------- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index a74f4dfd4f..a364ff937d 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -50,6 +50,7 @@ Document: - Does WildFile match against full name? Doc. For 1.39: + of column positions in wx-console. - Close STDOUT if debug_level == 0 - Add recycle event. - Add scratch pool event. @@ -1494,4 +1495,5 @@ Block Position: 0 chaos. - Run the regression scripts on Solaris and FreeBSD - Figure out how to package gui, and rescue programs. +- Add a .dir command to restore tree code to eliminate the problem diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index d7279c2f06..8cd59c918a 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -5,6 +5,9 @@ General: Changes to 1.37.41: 12Oct05 +- Add a .dir command that separates arguments with commas. It + is intended to be used in the tree routines to get a + machine readable output for GUIs like wx-console. - Make configure set dvd-handler to have execute permission. - Install dvd-handler as is done for other dvd-xxx scripts. - In block.c call dvd_write_part() to write last part rather diff --git a/bacula/src/dird/ua_tree.c b/bacula/src/dird/ua_tree.c index ed999b7991..ed9c3364fe 100644 --- a/bacula/src/dird/ua_tree.c +++ b/bacula/src/dird/ua_tree.c @@ -42,6 +42,7 @@ static int findcmd(UAContext *ua, TREE_CTX *tree); static int lscmd(UAContext *ua, TREE_CTX *tree); static int lsmarkcmd(UAContext *ua, TREE_CTX *tree); static int dircmd(UAContext *ua, TREE_CTX *tree); +static int dot_dircmd(UAContext *ua, TREE_CTX *tree); static int estimatecmd(UAContext *ua, TREE_CTX *tree); static int helpcmd(UAContext *ua, TREE_CTX *tree); static int cdcmd(UAContext *ua, TREE_CTX *tree); @@ -57,6 +58,7 @@ static struct cmdstruct commands[] = { { N_("cd"), cdcmd, _("change current directory")}, { N_("count"), countcmd, _("count marked files in and below the cd")}, { N_("dir"), dircmd, _("long list current directory, wildcards allowed")}, + { N_(".dir"), dot_dircmd, _("long list current directory, wildcards allowed")}, { N_("done"), donecmd, _("leave file selection mode")}, { N_("estimate"), estimatecmd, _("estimate restore size")}, { N_("exit"), donecmd, _("same as done command")}, @@ -64,7 +66,7 @@ static struct cmdstruct commands[] = { { N_("help"), helpcmd, _("print help")}, { N_("ls"), lscmd, _("list current directory, wildcards allowed")}, { N_("lsmark"), lsmarkcmd, _("list the marked files in and below the cd")}, - { N_("mark"), markcmd, _("mark dir/file to be restored recursively in dirs")}, + { N_("mark"), markcmd, _("mark dir/file to be restored recursively, wildcards allowed")}, { N_("markdir"), markdircmd, _("mark directory name to be restored (no files)")}, { N_("pwd"), pwdcmd, _("print current working directory")}, { N_("unmark"), unmarkcmd, _("unmark dir/file to be restored recursively in dir")}, @@ -461,7 +463,9 @@ extern char *getgroup(gid_t gid, char *name, int len); /* * This is actually the long form used for "dir" */ -static void ls_output(char *buf, const char *fname, const char *tag, struct stat *statp) +static void ls_output(char *buf, const char *fname, const char *tag, + struct stat *statp, bool dot_cmd) + { char *p; const char *f; @@ -470,27 +474,41 @@ static void ls_output(char *buf, const char *fname, const char *tag, struct stat int n; p = encode_mode(statp->st_mode, buf); - n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink); - p += n; - n = sprintf(p, "%-8.8s %-8.8s", getuser(statp->st_uid, en1, sizeof(en1)), - getgroup(statp->st_gid, en2, sizeof(en2))); - p += n; - n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1)); - p += n; - p = encode_time(statp->st_ctime, p); - *p++ = ' '; - *p++ = *tag; + if (dot_cmd) { + *p++ = ','; + n = sprintf(p, "%d,", (uint32_t)statp->st_nlink); + p += n; + n = sprintf(p, "%s,%s,", getuser(statp->st_uid, en1, sizeof(en1)), + getgroup(statp->st_gid, en2, sizeof(en2))); + p += n; + n = sprintf(p, "%s,", edit_uint64(statp->st_size, ec1)); + p += n; + p = encode_time(statp->st_ctime, p); + *p++ = ','; + *p++ = *tag; + *p++ = ','; + } else { + n = sprintf(p, " %2d ", (uint32_t)statp->st_nlink); + p += n; + n = sprintf(p, "%-8.8s %-8.8s", getuser(statp->st_uid, en1, sizeof(en1)), + getgroup(statp->st_gid, en2, sizeof(en2))); + p += n; + n = sprintf(p, "%10.10s ", edit_uint64(statp->st_size, ec1)); + p += n; + p = encode_time(statp->st_ctime, p); + *p++ = ' '; + *p++ = *tag; + } for (f=fname; *f; ) { *p++ = *f++; } *p = 0; } - /* * Like ls command, but give more detail on each file */ -static int dircmd(UAContext *ua, TREE_CTX *tree) +static int do_dircmd(UAContext *ua, TREE_CTX *tree, bool dot_cmd) { TREE_NODE *node; FILE_DBR fdbr; @@ -540,13 +558,23 @@ static int dircmd(UAContext *ua, TREE_CTX *tree) /* Something went wrong getting attributes -- print name */ memset(&statp, 0, sizeof(statp)); } - ls_output(buf, cwd, tag, &statp); + ls_output(buf, cwd, tag, &statp, dot_cmd); bsendmsg(ua, "%s\n", buf); } } return 1; } +int dot_dircmd(UAContext *ua, TREE_CTX *tree) +{ + return do_dircmd(ua, tree, true/*dot command*/); +} + +static int dircmd(UAContext *ua, TREE_CTX *tree) +{ + return do_dircmd(ua, tree, false/*not dot command*/); +} + static int estimatecmd(UAContext *ua, TREE_CTX *tree) { @@ -593,7 +621,10 @@ static int helpcmd(UAContext *ua, TREE_CTX *tree) bsendmsg(ua, _(" Command Description\n ======= ===========\n")); for (i=0; i