+ return ok;
+}
+
+static bool dot_bvfs_update(UAContext *ua, const char *cmd)
+{
+
+ if (!open_client_db(ua)) {
+ return 1;
+ }
+
+ int pos = find_arg_with_value(ua, "jobid");
+ if (pos != -1 && is_a_number_list(ua->argv[pos])) {
+ POOL_MEM jobids;
+ pm_strcpy(jobids, ua->argv[pos]);
+ bvfs_update_path_hierarchy_cache(ua->jcr, ua->db, jobids.c_str());
+ } else {
+ /* update cache for all jobids */
+ bvfs_update_cache(ua->jcr, ua->db);
+ }
+ return true;
+}
+
+static int bvfs_result_handler(void *ctx, int fields, char **row)
+{
+ UAContext *ua = (UAContext *)ctx;
+ struct stat statp;
+ int32_t LinkFI;
+ const char *fileid;
+ char *lstat;
+ char empty[] = "A A A A A A A A A A A A A A";
+
+ lstat = (row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty;
+ fileid = (row[BVFS_FileId] && row[BVFS_FileId][0])?row[BVFS_FileId]:"0";
+
+ memset(&statp, 0, sizeof(struct stat));
+ decode_stat(lstat, &statp, &LinkFI);
+
+ Dmsg1(100, "type=%s\n", row[0]);
+ if (bvfs_is_dir(row)) {
+ char *path = bvfs_basename_dir(row[BVFS_Name]);
+ ua->send_msg("%s\t0\t%s\t%s\t%s\t%s\n", row[BVFS_PathId], fileid,
+ row[BVFS_JobId], row[BVFS_LStat], path);
+
+ } else if (bvfs_is_file(row)) {
+ ua->send_msg("%s\t%s\t%s\t%s\t%s\t%s\n", row[BVFS_PathId],
+ row[BVFS_FilenameId], fileid, row[BVFS_JobId],
+ row[BVFS_LStat], row[BVFS_Name]);
+ }
+
+ return 0;
+}
+
+static bool bvfs_parse_arg(UAContext *ua,
+ DBId_t *pathid, char **path, char **jobid,
+ int *limit, int *offset)
+{
+ *pathid=0;
+ *limit=2000;
+ *offset=0;
+ *path=NULL;
+ *jobid=NULL;
+
+ for (int i=1; i<ua->argc; i++) {
+ if (strcasecmp(ua->argk[i], NT_("pathid")) == 0) {
+ if (is_a_number(ua->argv[i])) {
+ *pathid = str_to_int64(ua->argv[i]);
+ }
+ }
+ if (strcasecmp(ua->argk[i], NT_("path")) == 0) {
+ *path = ua->argv[i];
+ }
+
+ if (strcasecmp(ua->argk[i], NT_("jobid")) == 0) {
+ if (is_a_number_list(ua->argv[i])) {
+ *jobid = ua->argv[i];
+ }
+ }
+
+ if (strcasecmp(ua->argk[i], NT_("limit")) == 0) {
+ if (is_a_number(ua->argv[i])) {
+ *limit = str_to_int64(ua->argv[i]);
+ }
+ }
+
+ if (strcasecmp(ua->argk[i], NT_("offset")) == 0) {
+ if (is_a_number(ua->argv[i])) {
+ *offset = str_to_int64(ua->argv[i]);
+ }
+ }
+ }
+
+ if (!((*pathid || *path) && *jobid)) {
+ return false;
+ }
+
+ if (!open_client_db(ua)) {
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * .bvfs_lsfiles jobid=1,2,3,4 pathid=10
+ * .bvfs_lsfiles jobid=1,2,3,4 path=/
+ */
+static bool dot_bvfs_lsfiles(UAContext *ua, const char *cmd)
+{
+ DBId_t pathid=0;
+ int limit=2000, offset=0;
+ char *path=NULL, *jobid=NULL;
+
+ if (!bvfs_parse_arg(ua, &pathid, &path, &jobid,
+ &limit, &offset))
+ {
+ ua->error_msg("Can't find jobid, pathid or path argument\n");
+ return true; /* not enough param */
+ }
+
+ Bvfs fs(ua->jcr, ua->db);
+ fs.set_jobids(jobid);
+ fs.set_handler(bvfs_result_handler, ua);
+ fs.set_limit(limit);
+
+ if (pathid) {
+ fs.ch_dir(pathid);
+ } else {
+ fs.ch_dir(path);
+ }
+
+ fs.set_offset(offset);
+
+ fs.ls_files();
+
+ return true;
+}
+
+/*
+ * .bvfs_lsdirs jobid=1,2,3,4 pathid=10
+ * .bvfs_lsdirs jobid=1,2,3,4 path=/
+ * .bvfs_lsdirs jobid=1,2,3,4 path=
+ */
+static bool dot_bvfs_lsdirs(UAContext *ua, const char *cmd)
+{
+ DBId_t pathid=0;
+ int limit=2000, offset=0;
+ char *path=NULL, *jobid=NULL;
+
+ if (!bvfs_parse_arg(ua, &pathid, &path, &jobid,
+ &limit, &offset))
+ {
+ ua->error_msg("Can't find jobid, pathid or path argument\n");
+ return true; /* not enough param */
+ }
+
+ Bvfs fs(ua->jcr, ua->db);
+ fs.set_jobids(jobid);
+ fs.set_limit(limit);
+ fs.set_handler(bvfs_result_handler, ua);
+
+ if (pathid) {
+ fs.ch_dir(pathid);
+ } else {
+ fs.ch_dir(path);
+ }
+
+ fs.set_offset(offset);
+
+ fs.ls_special_dirs();
+ fs.ls_dirs();
+
+ return true;