]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/bvfs.c
Tweak some comments and formatting.
[bacula/bacula] / bacula / src / cats / bvfs.c
index 1cfcc934854c1468862a03da62b621089c8c6bf0..80a7cd71fdac2ff5027f17606956b078e754c2dc 100644 (file)
@@ -199,6 +199,15 @@ char *bvfs_parent_dir(char *path)
    char *p = path;
    int len = strlen(path) - 1;
 
+   /* windows directory / */
+   if (len == 2 && B_ISALPHA(path[0]) 
+                && path[1] == ':' 
+                && path[2] == '/')
+   {
+      len = 0;
+      path[0] = '\0';
+   }
+
    if (len >= 0 && path[len] == '/') {      /* if directory, skip last / */
       path[len] = '\0';
    }
@@ -436,7 +445,6 @@ void bvfs_update_cache(JCR *jcr, B_DB *mdb)
    db_list_ctx jobids_list;
 
    db_lock(mdb);
-   db_start_transaction(jcr, mdb);
 
 #ifdef xxx
    /* TODO: Remove this code when updating make_bacula_table script */
@@ -487,7 +495,6 @@ void bvfs_update_cache(JCR *jcr, B_DB *mdb)
 
    bvfs_update_path_hierarchy_cache(jcr, mdb, jobids_list.list);
 
-   db_end_transaction(jcr, mdb);
    db_start_transaction(jcr, mdb);
    Dmsg0(dbglevel, "Cleaning pathvisibility\n");
    Mmsg(mdb->cmd, 
@@ -827,6 +834,15 @@ static bool check_temp(char *output_table)
    return false;
 }
 
+void Bvfs::clear_cache()
+{
+   db_sql_query(db, "BEGIN",                     NULL, NULL);
+   db_sql_query(db, "UPDATE Job SET HasCache=0", NULL, NULL);
+   db_sql_query(db, "TRUNCATE PathHierarchy",    NULL, NULL);
+   db_sql_query(db, "TRUNCATE PathVisibility",   NULL, NULL);
+   db_sql_query(db, "COMMIT",                    NULL, NULL);
+}
+
 bool Bvfs::drop_restore_list(char *output_table)
 {
    POOL_MEM query;
@@ -843,7 +859,7 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
 {
    POOL_MEM query;
    POOL_MEM tmp, tmp2;
-   int64_t id, jobid;
+   int64_t id, jobid, prev_jobid;
    bool init=false;
    bool ret=false;
    /* check args */
@@ -858,6 +874,15 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
       return false;
    }
 
+   db_lock(db);
+
+   /* Cleanup old tables first */
+   Mmsg(query, "DROP TABLE btemp%s", output_table);
+   db_sql_query(db, query.c_str());
+
+   Mmsg(query, "DROP TABLE %s", output_table);
+   db_sql_query(db, query.c_str());
+
    Mmsg(query, "CREATE TABLE btemp%s AS ", output_table);
 
    if (*fileid) {               /* Select files with their direct id */
@@ -875,7 +900,7 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
       if (!db_sql_query(db, tmp.c_str(), get_path_handler, (void *)&tmp2)) {
          Dmsg0(dbglevel, "Can't search for path\n");
          /* print error */
-         return false;
+         goto bail_out;
       }
       if (!strcmp(tmp2.c_str(), "")) { /* path not found */
          Dmsg3(dbglevel, "Path not found %lld q=%s s=%s\n",
@@ -927,11 +952,11 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
    }
 
    /* expect jobid,fileindex */
-   int64_t prev_jobid=0;
+   prev_jobid=0;
    while (get_next_id_from_list(&hardlink, &jobid) == 1) {
       if (get_next_id_from_list(&hardlink, &id) != 1) {
          Dmsg0(dbglevel, "hardlink should be two by two\n");
-         return false;
+         goto bail_out;
       }
       if (jobid != prev_jobid) { /* new job */
          if (prev_jobid == 0) {  /* first jobid */
@@ -979,7 +1004,7 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
 
    /* MySQL need it */
    if (db_get_type_index(db) == SQL_TYPE_MYSQL) {
-      Mmsg(query, "CREATE INDEX idx_%s ON b2%s (JobId)", 
+      Mmsg(query, "CREATE INDEX idx_%s ON %s (JobId)", 
            output_table, output_table);
       Dmsg1(dbglevel_sql, "q=%s\n", query.c_str());
       if (!db_sql_query(db, query.c_str(), NULL, NULL)) {
@@ -993,6 +1018,7 @@ bool Bvfs::compute_restore_list(char *fileid, char *dirid, char *hardlink,
 bail_out:
    Mmsg(query, "DROP TABLE btemp%s", output_table);
    db_sql_query(db, query.c_str(), NULL, NULL);
+   db_unlock(db);
    return ret;
 }