]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_tree.c
kes Update copyright date in program files, and for the most part
[bacula/bacula] / bacula / src / dird / ua_tree.c
index 0f3b0f35ee4ef6b570fe0346029ebbb1706b37cd..606ad9bbba999df8c4b0c4f5fcfb3d8259c05d45 100644 (file)
@@ -9,7 +9,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2002-2005 Kern Sibbald
+   Copyright (C) 2002-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -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);
@@ -54,23 +55,24 @@ static int donecmd(UAContext *ua, TREE_CTX *tree);
 
 struct cmdstruct { const char *key; int (*func)(UAContext *ua, TREE_CTX *tree); const char *help; };
 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_("done"),       donecmd,      _("leave file selection mode")},
- { N_("estimate"),   estimatecmd,  _("estimate restore size")},
- { N_("exit"),       donecmd,      _("same as done command")},
- { N_("find"),       findcmd,      _("find files, wildcards allowed")},
- { 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_("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")},
- { N_("unmarkdir"),  unmarkdircmd, _("unmark directory name only no recursion")},
- { N_("quit"),       quitcmd,      _("quit and do not do restore")},
- { N_("?"),          helpcmd,      _("print help")},
+ { NT_("cd"),         cdcmd,        _("change current directory")},
+ { NT_("count"),      countcmd,     _("count marked files in and below the cd")},
+ { NT_("dir"),        dircmd,       _("long list current directory, wildcards allowed")},
+ { NT_(".dir"),       dot_dircmd,   _("long list current directory, wildcards allowed")},
+ { NT_("done"),       donecmd,      _("leave file selection mode")},
+ { NT_("estimate"),   estimatecmd,  _("estimate restore size")},
+ { NT_("exit"),       donecmd,      _("same as done command")},
+ { NT_("find"),       findcmd,      _("find files, wildcards allowed")},
+ { NT_("help"),       helpcmd,      _("print help")},
+ { NT_("ls"),         lscmd,        _("list current directory, wildcards allowed")},
+ { NT_("lsmark"),     lsmarkcmd,    _("list the marked files in and below the cd")},
+ { NT_("mark"),       markcmd,      _("mark dir/file to be restored recursively, wildcards allowed")},
+ { NT_("markdir"),    markdircmd,   _("mark directory name to be restored (no files)")},
+ { NT_("pwd"),        pwdcmd,       _("print current working directory")},
+ { NT_("unmark"),     unmarkcmd,    _("unmark dir/file to be restored recursively in dir")},
+ { NT_("unmarkdir"),  unmarkdircmd, _("unmark directory name only no recursion")},
+ { NT_("quit"),       quitcmd,      _("quit and do not do restore")},
+ { NT_("?"),          helpcmd,      _("print help")},
              };
 #define comsize (sizeof(commands)/sizeof(struct cmdstruct))
 
@@ -107,7 +109,8 @@ bool user_select_files_from_tree(TREE_CTX *tree)
       }
       parse_ua_args(ua);
       if (ua->argc == 0) {
-         break;
+         bsendmsg(tree->ua, _("Illegal command. Enter \"done\" to exit.\n"));
+         continue;
       }
 
       len = strlen(ua->argk[0]);
@@ -156,6 +159,8 @@ int insert_tree_handler(void *ctx, int num_fields, char **row)
    int FileIndex;
    JobId_t JobId;
 
+// Dmsg4(000, "Path=%s%s FI=%s JobId=%s\n", row[0], row[1],
+//    row[2], row[3]);
    if (*row[1] == 0) {                /* no filename => directory */
       if (*row[0] != '/') {           /* Must be Win32 directory */
          type = TN_DIR_NLS;
@@ -303,9 +308,11 @@ static int markcmd(UAContext *ua, TREE_CTX *tree)
    }
    if (count == 0) {
       bsendmsg(ua, _("No files marked.\n"));
+   } else if (count == 1) {
+      bsendmsg(ua, _("1 file marked.\n"));
    } else {
-      bsendmsg(ua, _("%s file%s marked.\n"),
-               edit_uint64_with_commas(count, ec1), count==0?"":"s");
+      bsendmsg(ua, _("%s files marked.\n"),
+               edit_uint64_with_commas(count, ec1));
    }
    return 1;
 }
@@ -332,9 +339,11 @@ static int markdircmd(UAContext *ua, TREE_CTX *tree)
    }
    if (count == 0) {
       bsendmsg(ua, _("No directories marked.\n"));
+   } else if (count == 1) {
+      bsendmsg(ua, _("1 directory marked.\n"));
    } else {
-      bsendmsg(ua, _("%s director%s marked.\n"),
-               edit_uint64_with_commas(count, ec1), count==1?"y":"ies");
+      bsendmsg(ua, _("%s directories marked.\n"),
+               edit_uint64_with_commas(count, ec1));
    }
    return 1;
 }
@@ -354,7 +363,7 @@ static int countcmd(UAContext *ua, TREE_CTX *tree)
          }
       }
    }
-   bsendmsg(ua, "%s total files/dirs. %s marked to be restored.\n",
+   bsendmsg(ua, _("%s total files/dirs. %s marked to be restored.\n"),
             edit_uint64_with_commas(total, ec1),
             edit_uint64_with_commas(num_extract, ec2));
    return 1;
@@ -455,36 +464,59 @@ 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;
    char ec1[30];
    char en1[30], en2[30];
    int n;
+   time_t time;
 
    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_mtime, 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;
+      if (statp->st_ctime > statp->st_mtime) {
+         time = statp->st_ctime;
+      } else {
+         time = statp->st_mtime;
+      }
+      /* Display most recent time */
+      p = encode_time(time, 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;
@@ -493,7 +525,7 @@ static int dircmd(UAContext *ua, TREE_CTX *tree)
    char cwd[1100], *pcwd;
 
    if (!tree_node_has_child(tree->node)) {
-      bsendmsg(ua, "Node %s has no children.\n", tree->node->fname);
+      bsendmsg(ua, _("Node %s has no children.\n"), tree->node->fname);
       return 1;
    }
 
@@ -534,13 +566,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)
 {
@@ -574,7 +616,7 @@ static int estimatecmd(UAContext *ua, TREE_CTX *tree)
          }
       }
    }
-   bsendmsg(ua, "%d total files; %d marked to be restored; %s bytes.\n",
+   bsendmsg(ua, _("%d total files; %d marked to be restored; %s bytes.\n"),
             total, num_extract, edit_uint64_with_commas(total_bytes, ec1));
    return 1;
 }
@@ -587,7 +629,10 @@ static int helpcmd(UAContext *ua, TREE_CTX *tree)
 
    bsendmsg(ua, _("  Command    Description\n  =======    ===========\n"));
    for (i=0; i<comsize; i++) {
-      bsendmsg(ua, _("  %-10s %s\n"), _(commands[i].key), _(commands[i].help));
+      /* List only non-dot commands */
+      if (commands[i].key[0] != '.') {
+         bsendmsg(ua, "  %-10s %s\n", _(commands[i].key), _(commands[i].help));
+      }
    }
    bsendmsg(ua, "\n");
    return 1;
@@ -606,6 +651,7 @@ static int cdcmd(UAContext *ua, TREE_CTX *tree)
    if (ua->argc != 2) {
       return 1;
    }
+   strip_leading_space(ua->argk[1]);
    node = tree_cwd(ua->argk[1], tree->root, tree->node);
    if (!node) {
       /* Try once more if Win32 drive -- make absolute */
@@ -654,8 +700,10 @@ static int unmarkcmd(UAContext *ua, TREE_CTX *tree)
    }
    if (count == 0) {
       bsendmsg(ua, _("No files unmarked.\n"));
+   } else if (count == 1) {
+      bsendmsg(ua, _("1 file unmarked.\n"));
    } else {
-      bsendmsg(ua, _("%d file%s unmarked.\n"), count, count==0?"":"s");
+      bsendmsg(ua, _("%d files unmarked.\n"), count);
    }
    return 1;
 }
@@ -683,8 +731,10 @@ static int unmarkdircmd(UAContext *ua, TREE_CTX *tree)
 
    if (count == 0) {
       bsendmsg(ua, _("No directories unmarked.\n"));
+   } else if (count == 1) {
+      bsendmsg(ua, _("1 directory unmarked.\n"));
    } else {
-      bsendmsg(ua, _("%d director%s unmarked.\n"), count, count==1?"y":"ies");
+      bsendmsg(ua, _("%d directories unmarked.\n"), count);
    }
    return 1;
 }