#define dbglevel 10
#define dbglevel_sql 15
+static int result_handler(void *ctx, int fields, char **row)
+{
+ if (fields == 4) {
+ Pmsg4(0, "%s\t%s\t%s\t%s\n",
+ row[0], row[1], row[2], row[3]);
+ } else if (fields == 5) {
+ Pmsg5(0, "%s\t%s\t%s\t%s\t%s\n",
+ row[0], row[1], row[2], row[3], row[4]);
+ } else if (fields == 6) {
+ Pmsg6(0, "%s\t%s\t%s\t%s\t%s\t%s\n",
+ row[0], row[1], row[2], row[3], row[4], row[5]);
+ } else if (fields == 7) {
+ Pmsg7(0, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
+ row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
+ }
+ return 0;
+}
+
+Bvfs::Bvfs(JCR *j, B_DB *mdb) {
+ jcr = j;
+ jcr->inc_use_count();
+ db = mdb; /* need to inc ref count */
+ jobids = get_pool_memory(PM_NAME);
+ pattern = get_pool_memory(PM_NAME);
+ *pattern = *jobids = 0;
+ dir_filenameid = pwd_id = offset = 0;
+ see_copies = see_all_version = false;
+ limit = 1000;
+ attr = new_attr(jcr);
+ list_entries = result_handler;
+ user_data = this;
+}
+
+Bvfs::~Bvfs() {
+ free_pool_memory(jobids);
+ free_pool_memory(pattern);
+ free_attr(attr);
+ jcr->dec_use_count();
+}
+
/*
* TODO: Find a way to let the user choose how he wants to display
* files and directories
return path;
}
-
-
-/* Return the basename of the with the trailing / (update the given string)
+/* Return the basename of the with the trailing /
* TODO: see in the rest of bacula if we don't have
* this function already
*/
db_unlock(mdb);
}
-
/*
* Find an store the filename descriptor for empty directories Filename.Name=''
*/
bvfs_update_path_hierarchy_cache(jcr, db, jobids);
}
-static int result_handler(void *ctx, int fields, char **row)
-{
- if (fields == 4) {
- Dmsg4(0, "%s\t%s\t%s\t%s\n",
- row[0], row[1], row[2], row[3]);
- } else if (fields == 5) {
- Dmsg5(0, "%s\t%s\t%s\t%s\t%s\n",
- row[0], row[1], row[2], row[3], row[4]);
- } else if (fields == 6) {
- Dmsg6(0, "%s\t%s\t%s\t%s\t%s\t%s\n",
- row[0], row[1], row[2], row[3], row[4], row[5]);
- } else if (fields == 7) {
- Dmsg7(0, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
- row[0], row[1], row[2], row[3], row[4], row[5], row[6]);
- }
- return 0;
-}
-
-static int result_path_handler(void *ctx, int fields, char **row)
-{
- if (fields == 4) {
- Dmsg4(0, "%s\t%s\t%s\t%s\n",
- row[0], bvfs_basename_dir(row[1]), row[2], row[3]);
- }
- return 0;
-}
-
/* Change the current directory, returns true if the path exists */
bool Bvfs::ch_dir(char *path)
{
,edit_uint64(fnid, ed1), edit_uint64(pathid, ed2), client, q.c_str(),
limit, offset);
- db_sql_query(db, query.c_str(), result_handler, this);
+ db_sql_query(db, query.c_str(), list_entries, user_data);
}
DBId_t Bvfs::get_root()
POOL_MEM query2;
Mmsg(query2,
-"SELECT tmp.PathId, tmp.Path, LStat, JobId "
+"SELECT tmp.PathId, tmp.Path, JobId, LStat "
"FROM %s AS tmp LEFT JOIN ( " // get attributes if any
"SELECT File1.PathId AS PathId, File1.JobId AS JobId, "
"File1.LStat AS LStat FROM File AS File1 "
query.c_str(), edit_uint64(dir_filenameid, ed2), jobids);
Dmsg1(dbglevel_sql, "q=%s\n", query.c_str());
- db_sql_query(db, query2.c_str(), result_handler, this);
+ db_sql_query(db, query2.c_str(), list_entries, user_data);
}
void Bvfs::ls_dirs()
*/
/* Then we get all the dir entries from File ... */
POOL_MEM query;
- Mmsg(query,
+ Mmsg(query,
+// 0 1 2 3
"SELECT PathId, Path, JobId, LStat FROM ( "
"SELECT Path1.PathId AS PathId, Path1.Path AS Path, "
"lower(Path1.Path) AS lpath, "
limit, offset);
Dmsg1(dbglevel_sql, "q=%s\n", query.c_str());
- db_sql_query(db, query.c_str(), result_path_handler, this);
+ db_sql_query(db, query.c_str(), list_entries, user_data);
}
void Bvfs::ls_files()
}
POOL_MEM query;
- Mmsg(query, // 0 1 2 3 4
-"SELECT File.FilenameId, listfiles.id, listfiles.Name, File.LStat, File.JobId "
+ Mmsg(query, // 0 1 2 3 4
+"SELECT File.FilenameId, listfiles.Name, File.JobId, File.LStat, listfiles.id "
"FROM File, ( "
"SELECT Filename.Name as Name, max(File.FileId) as id "
"FROM File, Filename "
limit,
offset);
Dmsg1(dbglevel_sql, "q=%s\n", query.c_str());
- db_sql_query(db, query.c_str(), result_handler, this);
+ db_sql_query(db, query.c_str(), list_entries, user_data);
}
#include "bacula.h"
#include "cats/cats.h"
#include "cats/bvfs.h"
+#include "findlib/find.h"
/* Local variables */
static B_DB *db;
" -P <password specify database password (default none)\n"
" -h <host> specify database host (default NULL)\n"
" -w <working> specify working directory\n"
+" -j <jobids> specify jobids\n"
+" -p <path> specify path\n"
+" -f <file> specify file\n"
" -v verbose\n"
" -? print this message\n\n"), 2001, VERSION, BDATE);
exit(1);
}
+static int result_handler(void *ctx, int fields, char **row)
+{
+ Bvfs *vfs = (Bvfs *)ctx;
+ ATTR *attr = vfs->get_attr();
+ char *empty = "";
+
+ if (fields == BVFS_DIR_RECORD || fields == BVFS_FILE_RECORD) {
+ decode_stat((row[BVFS_LStat])?row[BVFS_LStat]:empty,
+ &attr->statp, &attr->LinkFI);
+ if (fields == BVFS_DIR_RECORD) {
+ pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));
+ } else {
+ pm_strcpy(attr->ofname, row[BVFS_Name]);
+ }
+ print_ls_output(vfs->get_jcr(), attr);
+
+ } else {
+ Pmsg6(0, "%s\t%s\t%s\t%s\t%s\t%s",
+ row[0], row[1], row[2], row[3], row[4], row[5]);
+ }
+ return 0;
+}
+
+
/* number of thread started */
int main (int argc, char *argv[])
{
int ch;
+ char *jobids="1", *path=NULL, *file=NULL;
setlocale(LC_ALL, "");
bindtextdomain("bacula", LOCALEDIR);
textdomain("bacula");
OSDependentInit();
- while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?")) != -1) {
+ while ((ch = getopt(argc, argv, "h:c:d:n:P:Su:vf:w:?j:p:f:")) != -1) {
switch (ch) {
case 'd': /* debug level */
if (*optarg == 't') {
verbose++;
break;
+ case 'p':
+ path = optarg;
+ break;
+
+ case 'f':
+ path = optarg;
+ break;
+
+ case 'j':
+ jobids = optarg;
+ break;
+
case '?':
default:
usage();
bvfs_update_cache(bjcr, db);
Bvfs fs(bjcr, db);
+ fs.set_handler(result_handler, &fs);
- fs.set_jobids("1");
+ fs.set_jobids(jobids);
fs.update_cache();
- fs.ch_dir("");
- fs.ls_files();
- fs.ls_dirs();
+ if (path) {
+ fs.ch_dir(path);
+ fs.ls_special_dirs();
+ fs.ls_dirs();
+ fs.ls_files();
+ exit (0);
+ }
+
+
+ Pmsg0(0, "list /\n");
fs.ch_dir("/");
- fs.ls_files();
+ fs.ls_special_dirs();
fs.ls_dirs();
+ fs.ls_files();
+ Pmsg0(0, "list /tmp/\n");
fs.ch_dir("/tmp/");
- fs.ls_files();
+ fs.ls_special_dirs();
fs.ls_dirs();
+ fs.ls_files();
+ Pmsg0(0, "list /tmp/regress/\n");
fs.ch_dir("/tmp/regress/");
+ fs.ls_special_dirs();
fs.ls_files();
fs.ls_dirs();
- fs.set_jobid(1);
+ Pmsg0(0, "list /tmp/regress/build/\n");
fs.ch_dir("/tmp/regress/build/");
- fs.ls_files();
- fs.ls_dirs();
fs.ls_special_dirs();
+ fs.ls_dirs();
+ fs.ls_files();
+
fs.get_all_file_versions(1, 347, "zog4-fd");
char p[200];