+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) {
+ num_extract++;
+ }
+ }
+ }
+ 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;
+}
+
+
+