- tree_getpath(node, cwd, sizeof(cwd));
- fdbr.FileId = 0;
- fdbr.JobId = node->JobId;
- if (db_get_file_attributes_record(ua->jcr, ua->db, cwd, NULL, &fdbr)) {
- int32_t LinkFI;
- decode_stat(fdbr.LStat, &statp, &LinkFI); /* decode stat pkt */
- ls_output(buf, cwd, node->extract, &statp);
- bsendmsg(ua, "%s\n", buf);
- } else {
- /* Something went wrong getting attributes -- print name */
- bsendmsg(ua, "%s%s%s\n", node->extract?"*":"", node->fname,
- (node->type==TN_DIR||node->type==TN_NEWDIR)?"/":"");
- }
+ if (node->extract) {
+ tag = "*";
+ } else if (node->extract_dir) {
+ tag = "+";
+ } else {
+ tag = " ";
+ }
+ tree_getpath(node, cwd, sizeof(cwd));
+ fdbr.FileId = 0;
+ fdbr.JobId = node->JobId;
+ /*
+ * Strip / from soft links to directories.
+ * This is because soft links to files have a trailing slash
+ * when returned from tree_getpath, but db_get_file_attr...
+ * treats soft links as files, so they do not have a trailing
+ * slash like directory names.
+ */
+ if (node->type == TN_FILE && tree_node_has_child(node)) {
+ bstrncpy(buf, cwd, sizeof(buf));
+ pcwd = buf;
+ int len = strlen(buf);
+ if (len > 1) {
+ buf[len-1] = 0; /* strip trailing / */
+ }
+ } else {
+ pcwd = cwd;
+ }
+ if (db_get_file_attributes_record(ua->jcr, ua->db, pcwd, NULL, &fdbr)) {
+ int32_t LinkFI;
+ decode_stat(fdbr.LStat, &statp, &LinkFI); /* decode stat pkt */
+ } else {
+ /* Something went wrong getting attributes -- print name */
+ memset(&statp, 0, sizeof(statp));
+ }
+ ls_output(buf, cwd, tag, &statp, dot_cmd);
+ ua->send_msg("%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)
+{
+ int total, num_extract;
+ uint64_t total_bytes = 0;
+ FILE_DBR fdbr;
+ struct stat statp;
+ char cwd[1100];
+ char ec1[50];
+
+ total = num_extract = 0;
+ for (TREE_NODE *node=first_tree_node(tree->root); node; node=next_tree_node(node)) {
+ if (node->type != TN_NEWDIR) {
+ total++;
+ /* If regular file, get size */
+ if (node->extract && node->type == TN_FILE) {
+ num_extract++;
+ tree_getpath(node, cwd, sizeof(cwd));
+ fdbr.FileId = 0;
+ fdbr.JobId = node->JobId;
+ if (db_get_file_attributes_record(ua->jcr, ua->db, cwd, NULL, &fdbr)) {
+ int32_t LinkFI;
+ decode_stat(fdbr.LStat, &statp, &LinkFI); /* decode stat pkt */
+ if (S_ISREG(statp.st_mode) && statp.st_size > 0) {
+ total_bytes += statp.st_size;
+ }
+ }
+ /* Directory, count only */
+ } else if (node->extract || node->extract_dir) {
+ num_extract++;
+ }