* fs.ls_files();
*/
+/* Helper for result handler */
+typedef enum {
+ BVFS_FILE_RECORD = 'F',
+ BVFS_DIR_RECORD = 'D',
+ BVFS_FILE_VERSION = 'V'
+} bvfs_handler_type;
+
+typedef enum {
+ BVFS_Type = 0, /* Could be D, F, V */
+ BVFS_PathId = 1,
+ BVFS_FilenameId = 2,
+
+ BVFS_Name = 3,
+ BVFS_JobId = 4,
+
+ BVFS_LStat = 5, /* Can be empty for missing directories */
+ BVFS_FileId = 6, /* Can be empty for missing directories */
+
+ /* Only if File Version record */
+ BVFS_Md5 = 3,
+ BVFS_VolName = 4,
+ BVFS_VolInchanger = 5
+} bvfs_row_index;
+
class Bvfs {
public:
- 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;
- }
-
- virtual ~Bvfs() {
- free_pool_memory(jobids);
- free_pool_memory(pattern);
- jcr->dec_use_count();
- }
+ Bvfs(JCR *j, B_DB *mdb);
+ virtual ~Bvfs();
void set_jobid(JobId_t id) {
Mmsg(jobids, "%lld", (uint64_t)id);
* avoids mistakes with string encoding
*/
void ch_dir(DBId_t pathid) {
+ reset_offset();
pwd_id = pathid;
}
/*
* Returns true if the directory exists
*/
- bool ch_dir(char *path);
+ bool ch_dir(const char *path);
- void ls_files();
- void ls_dirs();
+ bool ls_files(); /* Returns true if we have more files to read */
+ bool ls_dirs(); /* Returns true if we have more dir to read */
void ls_special_dirs(); /* get . and .. */
- void get_all_file_versions(DBId_t pathid, DBId_t fnid, char *client);
+ void get_all_file_versions(DBId_t pathid, DBId_t fnid, const char *client);
void update_cache();
see_copies = val;
}
-private:
+ void set_handler(DB_RESULT_HANDLER *h, void *ctx) {
+ list_entries = h;
+ user_data = ctx;
+ }
+
+ DBId_t get_pwd() {
+ return pwd_id;
+ }
+
+ ATTR *get_attr() {
+ return attr;
+ }
+
+ JCR *get_jcr() {
+ return jcr;
+ }
+
+ void reset_offset() {
+ offset=0;
+ }
+
+ void next_offset() {
+ offset+=limit;
+ }
+
+ /* for internal use */
+ int _handle_path(void *, int, char **);
+
+private:
+ Bvfs(const Bvfs &); /* prohibit pass by value */
+ Bvfs & operator = (const Bvfs &); /* prohibit class assignment */
+
JCR *jcr;
B_DB *db;
POOLMEM *jobids;
uint32_t limit;
uint32_t offset;
+ uint32_t nb_record; /* number of records of the last query */
POOLMEM *pattern;
- DBId_t pwd_id;
- DBId_t dir_filenameid;
+ DBId_t pwd_id; /* Current pathid */
+ DBId_t dir_filenameid; /* special FilenameId where Name='' */
+ POOLMEM *prev_dir; /* ls_dirs query returns all versions, take the 1st one */
+ ATTR *attr; /* Can be use by handler to call decode_stat() */
bool see_all_version;
bool see_copies;
DBId_t get_dir_filenameid();
+
+ DB_RESULT_HANDLER *list_entries;
+ void *user_data;
};
+#define bvfs_is_dir(row) ((row)[BVFS_Type][0] == BVFS_DIR_RECORD)
+#define bvfs_is_file(row) ((row)[BVFS_Type][0] == BVFS_FILE_RECORD)
+
void bvfs_update_path_hierarchy_cache(JCR *jcr, B_DB *mdb, char *jobids);
void bvfs_update_cache(JCR *jcr, B_DB *mdb);
char *bvfs_parent_dir(char *path);