2 Bacula® - The Network Backup Solution
4 Copyright (C) 2009-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
18 * Program to test cache path
20 * Eric Bollengier, August 2009
26 #include "cats/cats.h"
27 #include "cats/sql_glue.h"
28 #include "cats/bvfs.h"
29 #include "findlib/find.h"
33 static const char *file = "COPYRIGHT";
35 static const char *db_name = "regress";
36 static const char *db_user = "regress";
37 static const char *db_password = "";
38 static const char *db_host = NULL;
44 "\nVersion: %s (%s)\n"
45 " -d <nn> set debug level to <nn>\n"
46 " -dt print timestamp in debug output\n"
47 " -n <name> specify the database name (default bacula)\n"
48 " -u <user> specify database user name (default bacula)\n"
49 " -P <password specify database password (default none)\n"
50 " -h <host> specify database host (default NULL)\n"
51 " -w <working> specify working directory\n"
52 " -j <jobids> specify jobids\n"
53 " -p <path> specify path\n"
54 " -f <file> specify file\n"
55 " -l <limit> maximum tuple to fetch\n"
56 " -T truncate cache table before starting\n"
58 " -? print this message\n\n"), 2001, VERSION, BDATE);
62 static int result_handler(void *ctx, int fields, char **row)
64 Bvfs *vfs = (Bvfs *)ctx;
65 ATTR *attr = vfs->get_attr();
66 char empty[] = "A A A A A A A A A A A A A A";
68 memset(&attr->statp, 0, sizeof(struct stat));
69 decode_stat((row[BVFS_LStat] && row[BVFS_LStat][0])?row[BVFS_LStat]:empty,
70 &attr->statp, sizeof(attr->statp), &attr->LinkFI);
72 if (bvfs_is_dir(row) || bvfs_is_file(row)) {
73 /* display clean stuffs */
75 if (bvfs_is_dir(row)) {
76 pm_strcpy(attr->ofname, bvfs_basename_dir(row[BVFS_Name]));
78 /* if we see the requested file, note his filenameid */
79 if (bstrcmp(row[BVFS_Name], file)) {
80 fnid = str_to_int64(row[BVFS_FilenameId]);
82 pm_strcpy(attr->ofname, row[BVFS_Name]);
84 print_ls_output(vfs->get_jcr(), attr);
87 Pmsg5(0, "JobId=%s FileId=%s\tMd5=%s\tVolName=%s\tVolInChanger=%s\n",
88 row[BVFS_JobId], row[BVFS_FileId], row[BVFS_Md5], row[BVFS_VolName],
89 row[BVFS_VolInchanger]);
91 pm_strcpy(attr->ofname, file);
92 print_ls_output(vfs->get_jcr(), attr);
98 /* number of thread started */
100 int main (int argc, char *argv[])
103 char *jobids = (char *)"1";
104 char *path=NULL, *client=NULL;
107 setlocale(LC_ALL, "");
108 bindtextdomain("bacula", LOCALEDIR);
109 textdomain("bacula");
112 Dmsg0(0, "Starting bvfs_test tool\n");
114 my_name_is(argc, argv, "bvfs_test");
115 init_msg(NULL, NULL);
119 while ((ch = getopt(argc, argv, "h:c:l:d:n:P:Su:vf:w:?j:p:f:T")) != -1) {
121 case 'd': /* debug level */
122 if (*optarg == 't') {
123 dbg_timestamp = true;
125 debug_level = atoi(optarg);
126 if (debug_level <= 0) {
132 limit = str_to_int64(optarg);
148 working_directory = optarg;
156 db_password = optarg;
189 Pmsg0(0, _("Wrong number of arguments: \n"));
192 JCR *bjcr = new_jcr(sizeof(JCR), NULL);
193 bjcr->JobId = getpid();
194 bjcr->setJobType(JT_CONSOLE);
195 bjcr->setJobLevel(L_FULL);
196 bjcr->JobStatus = JS_Running;
197 bjcr->client_name = get_pool_memory(PM_FNAME);
198 pm_strcpy(bjcr->client_name, "Dummy.Client.Name");
199 bstrncpy(bjcr->Job, "bvfs_test", sizeof(bjcr->Job));
201 if ((db = db_init_database(NULL, NULL, db_name, db_user, db_password,
202 db_host, 0, NULL, false, false)) == NULL) {
203 Emsg0(M_ERROR_TERM, 0, _("Could not init Bacula database\n"));
205 Dmsg1(0, "db_type=%s\n", db_get_type(db));
207 if (!db_open_database(NULL, db)) {
208 Emsg0(M_ERROR_TERM, 0, db_strerror(db));
210 Dmsg0(200, "Database opened\n");
212 Pmsg2(000, _("Using Database: %s, User: %s\n"), db_name, db_user);
218 Pmsg0(0, "Clean old table\n");
219 db_sql_query(db, "DELETE FROM PathHierarchy", NULL, NULL);
220 db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
221 db_sql_query(db, "DELETE FROM PathVisibility", NULL, NULL);
222 bvfs_update_cache(bjcr, db);
226 fs.set_handler(result_handler, &fs);
228 fs.set_jobids(jobids);
235 fs.ls_special_dirs();
237 while (fs.ls_files()) {
241 if (fnid && client) {
242 Pmsg0(0, "---------------------------------------------\n");
243 Pmsg1(0, "Getting file version for %s\n", file);
244 fs.get_all_file_versions(fs.get_pwd(), fnid, client);
251 Pmsg0(0, "list /\n");
253 fs.ls_special_dirs();
257 Pmsg0(0, "list /tmp/\n");
259 fs.ls_special_dirs();
263 Pmsg0(0, "list /tmp/regress/\n");
264 fs.ch_dir("/tmp/regress/");
265 fs.ls_special_dirs();
269 Pmsg0(0, "list /tmp/regress/build/\n");
270 fs.ch_dir("/tmp/regress/build/");
271 fs.ls_special_dirs();
275 fs.get_all_file_versions(1, 347, "zog4-fd");
278 strcpy(p, "/tmp/toto/rep/");
280 if(strcmp(p, "/tmp/toto/")) {
281 Pmsg0(000, "Error in bvfs_parent_dir\n");
284 if(strcmp(p, "/tmp/")) {
285 Pmsg0(000, "Error in bvfs_parent_dir\n");
289 Pmsg0(000, "Error in bvfs_parent_dir\n");
293 Pmsg0(000, "Error in bvfs_parent_dir\n");
297 Pmsg0(000, "Error in bvfs_parent_dir\n");